我正在使用JSONP,并且我的url(action)正在返回名为processTemplates的函数。 有什么办法可以执行我自己的功能,而不是 processTemplates。执行您自己的JSONP函数
像 _processJSONCallBack
function _processOverideCallBack(actionName) {
$.ajax({
type: 'GET',
url: actionName,
async: false,
contentType: "application/javascript",
jsonpCallback: '_processJSONCallBack',
dataType: "jsonp",
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
};
但是,当我试图尽自己抛出异常“请求JSON解析失败。”
请帮我解决这个问题。
甚至当我试图非同步=真它给了我同样的错误 – user2985842
然而,当我在我的Ajax调用成功尝试:功能(响应){ \t \t _processJSONCallBack(响应); \t}。神奇的是,它的工作 – user2985842