我在http://www.example.com/file.json有一个json文件。我用这个函数调用它但它没有工作。我看不出它有什么问题。该文件位于正确的位置,我可以查看它。
function privateyStandards(){
var callSite = "http://www.example.com/file.json";
var privateStandards = {
"cache": false,
// Use JSONP to work around cross-site scripting limitations.
"dataType": "jsonp",
"url": callSite
};
var privateRequest = $.ajax(privateStandards);
privateRequest.done(function(data){
console.log('enter');
//does not enter
});
}
以下是JSON文件中的内容
{
"copy":"2014",
"itemprop":"Title",
"privacyStatement":"URL",
"identityStandards":"URL",
"usePolicy":"URL",
"casIT":"URL"
}
更新
apsillers是正确的,我相应地更改了JSON文件和对json文件的调用。
function privateyStandards(){
var callSite = "http://www.example.com/file.json";
var privateStandards = {
"cache": false,
// Use JSONP to work around cross-site scripting limitations.
"dataType": "jsonp",
"url": callSite,
async: false,
contentType: "application/json",
jsonpCallback: 'jsonCallback',
dataType: 'jsonp'
};
var privateRequest = $.ajax(privateStandards);
privateRequest.done(function(data){
alert(data.copy);
});
}
在json文件中我改为
jsonCallback(
{
"copy":"2014",
"itemprop":"Title",
"privacyStatement":"URL",
"identityStandards":"URL",
"usePolicy":"URL",
"casIT":"URL"
}
);