I test a lot with the 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 result in the correct MIME type for the JSON data.
Philip schlump
source share