[jQuery] Strange errors with $.ajax()
I'd like just to report some minor problem, that is quite hard to
debug and it can cause a lot a temporary nightmare.
Assume you have the following query parameters:
var p = [{ "query": "myQueryString" }]; // badly defined query
string.. should not be an array
You now try to make a simple AJAX JSON call like:
$.ajax({
type: "POST",
url: "myurl.txt",
// serialize the array of data
data: $.param(p),
// we expect JSON data coming back
dataType: "json",
// wait for the request to finish successfully
error: function() {
console.log('failure');
},
success: function() {
console.log("success");
}
});
In Firefox running this code works, besides the fact the the query url
sent to the server looks like "murl.txt?undefined=undefined"
However in MSIE 6 or 7 you will get a strange error, where error
string is "parse error undefined".
When you set the http method to "GET" you will fix this error in MSIE
7, however the JSON results passed as arguments to a callback
functions are "somehow corrupted" - I mean there are not undefined,
but the result string does contain actually some garbage..
You will maybe try debug the json input file - to fix potential
syntactic errors, or you will try to change the Content-Type of the
file on the server, or whatever else..
The solution in fact will be to fix the query parameters, e.g. to
something like:
var p = { "query": "myQueryString" };
Just a reminder for anyone spending his time with hard to debug errors
in MSIE..
Regards
--
Milos