title: how do I return two JSON arrays from an .ajax Call?
body: <p>I'm using jqPlot and since I can't find one decent place to find out how to send multiple series to jqplot through JSON, I will try to work around it.</p>
  
  <p><em>so here's a little background:</em></p>
  
  <p>Right now, I can call my servlet and return a JSON array with the data that I'm going to display in the chart.</p>
  
  <p><strong>AJAX CALL</strong></p>
  
  <pre><code>$.ajax({
              type:   'POST',
              cache:  'false',
              data:   params,             
              url:    '/miloWeb/PlotChartServlet',
              async:  false,
              dataType: 'json',
              success: function(series){                  
                  coordinates =  [series] ;
              },
              error: function (xhr, ajaxOptions, thrownError){
                  alert(ajaxOptions);
              }   
          });
  </code></pre>
  
  <p><strong>SERVLET</strong></p>
  
  <pre><code>    private void generateCoordinates(HttpServletRequest request, HttpServletResponse response) throws IOException{
  
      JSONArray coordinates = new JSONArray();
      try {
          coordinates = findChartCoordinatesByPatientPK();
      } catch (JSONException e) {
          e.printStackTrace();
      }
      response.getOutputStream().print(coordinates.toString());
  
  }
  </code></pre>
  
  <p>What this does is return the string:</p>
  
  <blockquote>
    <p>[["07/06/2000","22.0"],["08/06/2000","20.0"],["08/06/2003","15.0"],["08/06/2005","35.0"],["08/06/2007","12.0"],["08/06/2010","10.0"],["08/06/2012","10.0"]]</p>
  </blockquote>
  
  <p>So I store that in the variable 'coordinates' and use those to plot the jqPlot graph using:</p>
  
  <pre><code>var plot10 = $.jqplot ('chartdiv', coordinates);
  </code></pre>
  
  <p><em>Up To this point everything works great, now comes what I'm trying to achieve:</em></p>
  
  <p>If I hardcode a String that symbolizes the two arrays inside another array, like so:</p>
  
  <pre><code>[[["07/06/2000","22.0"],["08/06/2000","20.0"],["08/06/2003","15.0"],["08/06/2005","35.0"],["08/06/2007","12.0"],["08/06/2010","10.0"],["08/06/2012","10.0"]], [["07/06/2000","21.0"],["08/06/2000","19.0"],["08/06/2003","14.0"],["08/06/2005","34.0"],["08/06/2007","11.0"],["08/06/2010","9.0"],["08/06/2012","9.0"]]]
  </code></pre>
  
  <p>I can get the jQplot to plot the two distinct lines in the chart! So I tried doing the same and returning a String exactly like that one through the servlet:</p>
  
  <p><strong>NOT WORKING SERVLET</strong></p>
  
  <pre><code>    private void generateCoordinates(HttpServletRequest request, HttpServletResponse response) throws IOException{
          JSONArray coordinates = new JSONArray();
          JSONArray coordinates2 = new JSONArray();
          try {
              coordinates = VitalsBB.findChartCoordinatesByPatientPK();
              coordinates2 = VitalsBB.findChartCoordinatesByPatientPK2();
          } catch (JSONException e) {
              e.printStackTrace();
          }
          response.getOutputStream().print( coordinates.toString() + ", " + coordinates2.toString());
  
      }
  </code></pre>
  
  <p>But that doesn't work, it gives me a parse Error. So do I need to modify the AJAX call? or is there a way to give back two <code>JSON arrays.toString()</code> to my form and store them in a variable? Or maybe I need two variables?</p>