Updated: I am sending HTML FORM data, but expect to receive JSON data. I am not trying to get POST JSON data.
I am trying to get a JSON response from an HTML FORM POST request. I successfully got JSON back when using a simple HTML FORM POST request (i.e. Not AJAX). My JSON response from HTML FORM POST:
{"success":true,"data":1234567}
The problem occurs when I try to process the request and response using jQuery.ajax ().
$.ajax({ type: "POST", url: URL, data: data1, dataType: "json", success: function(data, textStatus, jqXHR) { alert ("success"); }, error: function(xhr, status, error) { alert ("Error: " + error); } });
After executing the above code and debugging in Firebug, it seems that the POST request passes, but something is wrong when processing the response. Firebug tells me the following regarding the HTTP response from the POST request:
Response Headers Cache-Control private Content-Length 31 Content-Type application/json; charset=utf-8 ...
So it seems that 31 bytes of data are being sent. However, when debugging the actual Javascript, the error function and the xhr object are called:
Object { readyState=0, status=0, statusText="error"}
I know that the jQuery.ajax () document states that "In jQuery 1.4, JSON data is processed strictly, any rejected JSON is rejected and a parsing error occurs." However, I believe my JSON is valid as I tested it on jsonlint.com.
What else could be wrong?