jQuery Ajax always returns “undefined”?

后端 未结 1 1881
深忆病人
深忆病人 2021-01-15 19:24
  function getThisFrame(frameId) {
    var r;
    $.ajax({
        type: \"POST\",
        contentType: \"application/json\",
        url: \"abcdefg.asmx/RetriveThis         


        
相关标签:
1条回答
  • 2021-01-15 19:41

    you are returning result.d to $.ajax() not to getThisFrame().

    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.
    });
    
    0 讨论(0)
提交回复
热议问题