jQuery ajax代码可以从另一个域名或另一个网站调用Web服务吗?
以下是我amm使用的代码,
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
url: "https://developers.google.com/public/oauth2/1/files",
headers: {
'Authorization': headerDATA,
'Content-Type': 'application/json'
},
success: function (data) {
alert("Success");
for (var i = 0; i < data.items.length; i++) {
alert(AJAX);
}
},
error: function (e) {
alert("Failure");
alert(JSON.stringify(e));
}
});
如何解决这个问题?
最佳答案
当然可以
您的问题是由于网址中没有双引号引起的。 Ajax中的url字段应为字符串值。试试下面的代码
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
url: "https://developers.google.com/public/oauth2/1/files",
headers: {
'Authorization': headerDATA,
'Content-Type': 'application/json'
},
success: function (data) {
alert("Success");
for (var i = 0; i < data.items.length; i++) {
alert(data.items[i]);
}
},
error: function (e) {
alert("Failure");
alert(JSON.stringify(e));
}
});
关于javascript - 如何在asp.net中调用Jquery AJAX外部URl?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49870752/