I know that's some kind of callback concept, but have no idea how to do that.
$.ajax({
'url': '/test/',
'type': 'POST',
'data': {'age': age},
'dataType': 'html',
'success': function(data, textStatus, xhr) {
//I want when the data arrives, then execute another 开发者_Go百科function, because the function is too big to place here.
}
});
If you need to execute only some other function with takes the data as a parameter, do this:
$.ajax({
'url': '/test/',
'type': 'POST',
'data': {'age': age},
'dataType': 'html',
'success': myFunction
});
//then, defined anywhere that's in scope:
function myFunction(data) {
//do something with data
}
If you need to do some work then call that function...do just that:
$.ajax({
'url': '/test/',
'type': 'POST',
'data': {'age': age},
'dataType': 'html',
'success': function(data) {
//do stuff...
myFunction(data);
}
});
精彩评论