title: Ajax POST returns undefined error from a ashx page
body: <p>I keep receiving the undefined error. Here is the ajax method.</p>
  <pre><code>function testing() {
      var data = JSON.stringify(
          {
              &quot;TestID1&quot;: &quot;12345&quot;,
              &quot;TestID2&quot;: &quot;12345&quot;,
              &quot;TestID3&quot;: &quot;12345&quot;,
          });
      $.ajax({
          type: &quot;POST&quot;,
          url: &quot;Test.ashx&quot;,
          data: data,
          //async: false,
          //cache: false,
          contentType: &quot;application/json; charset=utf-8&quot;,
          dataType: &quot;json&quot;,
          success: function (response) {
              alert(response.ID);
          },
          error: function (jqXHR, textStatus, errorThrown) {
              alert(jqXHR.status);
              alert(textStatus);
              alert(errorThrown);
          }
      });
  }
  </code></pre>
  <p>Here is the controller/handler.</p>
  <pre><code>        public void ProcessRequest(HttpContext context)
          {
              string jsonString = String.Empty;
              HttpContext.Current.Request.InputStream.Position = 0;
              using (StreamReader inputStream = new StreamReader(HttpContext.Current.Request.InputStream))
              {
                  jsonString = inputStream.ReadToEnd();
                  JavaScriptSerializer jSerialize = new JavaScriptSerializer();
                  var receipt = jSerialize.Deserialize&lt;Receipt&gt;(jsonString);
  
                  if (receipt != null)
                  {
                      InsertData(receipt.TestID1, receipt.TestID1, receipt.TestID1);
                      var wrapper = new { ID = receipt.TestID1};
                      context.Response.Write(JsonConvert.SerializeObject(wrapper));
                      //context.Response.Write(&quot;{ \&quot;data\&quot;: [1,2,3] }&quot;);
                      //context.Response.End();
                  }
              }
          }
  
          public bool IsReusable
          {
              get
              {
                  return false;
              }
          }
  </code></pre>
  <p>Right now I am getting undefined error, but I was getting the &quot;JSON.parse: unexpected end of data at line 1 column 1 of the JSON data&quot; until recently. The data that is being posted is working since the InsertData() function inserts the correct data. I also tried setting the async function in the ajax method to false, but no luck. Also, tried sending specific responses (like the one commented out) and so far none have succeeded.</p>