I have the following ajax request:
jQuery.ajax({
async: true,
type: \"GET\",
url: url,
data: data,
I do a lot of testing with file: urls instead of using a web server. My JSON code will always have the wrong MIME type. To take care of this I use the following code:
$(document).ready(
function (){
myData = {};
$.ajax({
type: "GET",
// url: "json.php?fn=jsonData.json", // with Apache
url: "jsonData.json", // As a file:/// URL
contentType: "application/json; charset=utf-8",
data: myData,
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/json; charset=UTF-8");
}
},
dataType: "json",
success: function(returnData){
$("#jsonData").html("Success:"+returnData.tag);
},
error: function(returnData) {
$("#jsonData").html("Error:"+returnData.tag);
}
});
}
);
This will force the MIME type to be correct for JSON data.