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);
}
精彩评论