jQuery的阿贾克斯总是返回"不确定"?不确定、jQuery、阿贾克斯、QUOT

由网友(刘德华山东分华)分享简介:function getThisFrame(frameId) {var r;$.ajax({type: "POST",contentType: "application/json",url: "abcdefg.asmx/RetriveThis",data: "{Id:" + Id + "}",dataType: '...
  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.
});
阅读全文

相关推荐

最新文章