instead of writing code in the standard way:
$.get('test.xml',function(){
//manipulate the code here
})
I wanted to write the code this way to make things easier:
$.get('test.xml',callback(data));
function callback(data){
//manipulate with the data below...
}
but error show “data is undefined”, how can i fix this?
Just write
When you write
then
callbackgets executed immediately (you call the function).Or if
datais not supposed to be the data returned from the Ajax call, but some parameter you want to pass to the function, you have two possibilities:callbackreturn a function.Wrap the
callbackcall in an anonymous function: