我有以下功能很好,我使用 JSONP 来克服跨域,编写了一个 http 模块来更改内容类型,并且没有在 url 中附加回调名称。
function AddSecurityCode(securityCode, token) {
var res=0;
$.ajax({ url: "http://localhost:4000/External.asmx/AddSecurityCode",
data: { securityCode: JSON.stringify(securityCode),
token: JSON.stringify(token)
},
dataType: "jsonp",
success: function(json) {
alert(json); //Alerts the result correctly
res = json;
},
error: function() {
alert("Hit error fn!");
}
});
return res; //this is return before the success function? not sure.
}
res 变量总是未定义。而且我不能将 async=false 与 jsonp 一起使用。那么我怎样才能将结果返回到函数外部呢?我当然需要为后续调用这样做。
请指教,谢谢。问题是我不能在这个函数之外返回结果值