开发者

Jquery get() confusion with callback syntax

I want to specify a function to be run as my callback as past the get() response to do it, I can't figure out the correct syntax for this, I can correctly do this:

function GetXML() {
    $.ajax({
        url: '/scripts/test.json',
        success: tester(data)
        success: function (data) {
            myCustomFunction(data)
        }
    });
}
function myCustomFunction(data) {
   开发者_Go百科 alert("fire"+data);
}

but what I want to do is this: (which fails)

function GetXML() {
    $.ajax({
        url: '/scripts/test.json',
        success: myCustomFunction(data)
        }
    });
}
function myCustomFunction(data) {
    alert("fire"+data);
}


Easy:

function myCustomFunction(data) {
    alert("fire"+data);
}

function GetXML() {
    $.ajax({
        url: '/scripts/test.json',
        success: myCustomFunction
    });
}


I'm not sure, but this might work.

function GetXML() {
    $.ajax({
        url: '/scripts/test.json',
        success: myCustomFunction
        }
    });
}
function myCustomFunction(data) {
    alert("fire"+data);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜