Jquery AJAX请求不起作用&x27;JSON'中的意外字符串;
我试图进行下面的AJAX调用,但每次都失败了Jquery AJAX请求不起作用&x27;JSON'中的意外字符串;,jquery,ajax,Jquery,Ajax,我试图进行下面的AJAX调用,但每次都失败了 var getServerUrl = function(){ $.ajax({ 'url': 'config.json', 'contentType' : 'application/json', 'async': false, success: function(response) { if (!response.errorCode) {
var getServerUrl = function(){
$.ajax({
'url': 'config.json',
'contentType' : 'application/json',
'async': false,
success: function(response) {
if (!response.errorCode) {
serverURL = response.serverUrl;
getAccessToken();
}
},
error: function(XMLHttpRequest, textStatus, error) {
console.log(error);
}
});
}
控制台中记录的错误显示:
位置1810处JSON中出现意外字符串
试试这个
var getServerUrl=function(){
$.ajax({
url:'config.json',
contentType:'应用程序/json',
async:false,
成功:功能(响应){
如果(!response.errorCode){
serverURL=response.serverURL;
getAccessToken();
}
},
错误:函数(XMLHttpRequest、textStatus、error){
log(JSON.parse(error));
}
});
}
试试这个..
1)删除async:false
2)请向我们显示从请求返回的响应文本您确定错误消息不是来自JSON.parse(error)
本身吗?你为什么还要解析错误消息?你从console.log(error)中得到了什么
?@JJJ:删除JSON.parse(错误)后,我仍然会收到相同的错误,即位置1810处的JSON中出现意外字符串。@TechHunger您应该使用异步代码。使用sync没有任何借口,除非在onbeforeunload
Quoted或unquoted键中运行请求与OP遇到的错误无关。