tags:

views:

34

answers:

1
  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!

+4  A: 

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.
});
jAndy
Thank you very much, I did it.