jQuery的阿贾克斯总是返回"不确定"? [英] jQuery Ajax always returns "undefined"?

查看:123
本文介绍了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.
});

这篇关于jQuery的阿贾克斯总是返回"不确定"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆