加入跨域支持后ajax请求返回Uncaught SyntaxError: Unexpected token :

前端之家收集整理的这篇文章主要介绍了加入跨域支持后ajax请求返回Uncaught SyntaxError: Unexpected token :前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本来正常的代码,加入跨域支持dataType: 'JSONP',

$.ajax({
//contenType: "application/x-www-form-urlencoded",
type: "GET",
dataType: 'JSONP',
url: 'http://'+element.vm.ip+':8034/Monitor/StartMonitorMachine',
//url: 'http://localhost:58949/Monitor/StartMonitorMachine',

data: {
"configId": stdetailsvm.monitorConfigList[i].id,
"ReCallUrl": "http://172.16.13.10:8008",
"ip":element.vm.ip
},
success: function (data) {
if (data.Data == "0") {

} else {
alert("向服务器发送监控指令失败。"+data.Message);
}
},
error: function (data) {
alert(data.retMSG);
}
});

返回数据如下:{"Data":"0","StateCode":0,"Message":""}

但是Console里面有Uncaught SyntaxError: Unexpected token :报错


原因:Message空导致


解决方法:使Message返回数据

原文链接:https://www.f2er.com/ajax/161862.html

猜你在找的Ajax相关文章