jQuery的阿贾克斯总是返回"不确定"?
问题描述:
function getThisFrame(frameId) {
var r;
$.ajax({
type: "POST",
contentType: "application/json",
url: "abcdefg.asmx/RetriveThis",
data: "{Id:" + Id + "}",
dataType: 'json',
success: function (result) {
return result.d
}
});
}
返回值始终为未定义?我怎么能解决这个问题?谢谢!
The return value is always "undefined"? How could I solve this? Thanks!
中的数据肯定是没有问题的!
The data is surely no problem!
答
您正在返回 result.d
到 $。阿贾克斯()
不要 getThisFrame()
。
您需要回调的somekind的,如果你要处理 result.d
不知。
You need somekind of callback if you want to handle result.d
somehow.
function getThisFrame(frameId, callback) {
var r;
$.ajax({
type: "POST",
contentType: "application/json",
url: "abcdefg.asmx/RetriveThis",
data: "{Id:" + Id + "}",
dataType: 'json',
success: function (result) {
if(typeof callback === 'function') callback.apply(this, [result.d]);
}
});
}
getThisFrame(5, function(data){
// do something with data.
});