I have determined that my JSON, coming from the server, is valid (making the ajax call manually), but I would really like to use JQuery. I have also determined that the "post" URL, being sent to the server, is correct, using firebug. However, the error callback is still being triggered (parse error). I also tried datatype: text.
Are there other options that I should include?
$(function() {
$("#submit").bind("click", function() {
$.ajax({
type: "post",
url: "http://myServer/cgi-bin/broker" ,
datatype: "json",
data: {'start' : start,'end' : end},
error: function(request,error){
alert(error);
},
success: function(request) {
alert(request.length);
}
}); // End ajax
}); // End bind
}); // End eventlistener
Here are a few suggestions I would try:
1) the 'datatype' option you have specified should be 'dataType' (case-sensitive I believe)
2) try using the 'contentType' option as so:
contentType: "application/json; charset=utf-8"
I'm not sure how much that will help as it's used in the request to your post url, not in the response. See this article for more info: http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax (It's written for asp.net, but may be applicable)
3) Triple check the output of your post url and run the output through a JSON validator just to be absolutely sure it's valid and can be parsed into a JSON object. http://www.jsonlint.com
Hope some of this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With