title: How to accept a JSON string array in an .aspx Page method
body: <p>I am using jQuery ajax to pass a string array to a page method. I need to know what to do with that data once it gets to that page method. My goal is to insert it into a DB but before that I need to make sense of the array. As it is, it is coming over like this: { data : theArray} which correlates to {data: 1,2,3,4,5,6}. But 4,5, and 6 represent another row in the underlying DB and so would 7,8 and 9, and so on and so forth. I am new to Ajax.</p>
  
  <p>Here is the jQuery:</p>
  
  <pre><code>//packaging table data for submit to server
              $("#saveToDB").click(function() {
                  var dataForSubmit = new Array();
                  //gather all data to array except the "delete" cell, .rowToDelete
                  $('#QueueTable tbody td:not(.rowToDelete)').each(function() {
                      dataForSubmit.push($(this).html());
                  });
                  //send array to method
                  callScriptMethod('DailyReceipts.aspx/saveData', { theData: dataForSubmit });
              });
  
              function callScriptMethod(url, jsonObject, callback, async) {
  
                  callback = callback || function() { };
                  async = (async == null || async);
  
                  $.ajax({
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      url: url,
                      data: JSON.stringify(jsonObject),
                      dataType: "json",
                      async: async,
                      success: function(jsonResult) {
                          if ('d' in jsonResult)
                              callback(jsonResult.d);  
                          else
                              callback(jsonResult);
                      },
                      error: function() {
                          alert("Error calling '" + url + "' " + JSON.stringify(jsonObject));
                          callback([]);
                      }
                  });
              }
  </code></pre>
  
  <p>And here is the page method, made static and as a [WebMethod]:</p>
  
  <pre><code>   [WebMethod]
          public static void saveData(string[] theData)
          {
  
              //iterate the array
              for (int i = 0; i &lt; theData.Length; i++)
              {
  
              }
  
          }
  </code></pre>