私はうまく機能する次の関数を持っています、私はクロスドメインを克服するために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変数は常に未定義です。そして、jsonpでasync=falseを使用することはできません。では、どうすれば関数の外部に結果を返すことができますか?そして、私は確かに後続の呼び出しのためにそれを行う必要があります。
アドバイスをお願いします、ありがとう。問題は、この関数の外で結果値を返すことができないことです