Using a unparseable cruft on my ajax responses.
Works great, except IE7 which throws a failure. Any thoughts on why the failure?
ajax call:
$.ajax({
type: "POST",
url: "js/zipcodeLookup.json", //mock json response
contentType: "application/json",
dataType:"text json",
data: "{postalcode: '" + $(myField).val() + "', country: '" + myCountry + "'}",
success: function(data) {
//do something here
},
error: function(){
alert('failure');
}
});
ajax converter:
$.ajaxSetup({
converters: { "text json": function (stringData) {
return JSON.parse(stringData.replace('for(;;);', ''));
} }
});
and json:
for(;;);{
"isError": "false",
"city": "Springfield",
"juris": "IL"
}
EDIT
and the correct answer is that I stupidly overlooked my parse method - use jQuery.parseJSON()
instead!