ajax converters and IE7
-
13-06-2021 - |
Frage
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!
Lösung
IE < 8 doesn't have native support for JSON
. Do you have any fallback mechanism for IE7?
For browsers without native JSON support you should use this library
You could implement a fallback mechanism like this
<script>window.JSON||
document.write("<script src='js/json2.js'>\x3C/script>")
</script>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow