I’m trying to get the success data from a jquery Ajax call so I can use it elsewhere but for some reason its only accessible within the actual success call, so immeditaly below works but the other doesnt’.. any advice is appreciated
success: function(data) {
alert (data)
}
this doesn’t work when I try to pass “data” onto another function
$.ajax({
type: 'POST',
url: 'http://localhost/site1/utilities/ajax_component_call_handler',
data: {
component_function: component_function,
param_array: param_array
},
dataType: "json",
success: function(data) {
receiver (data)
}
});
}
my ajax success is calling this:
function receiver (data) {
ajax_return = data
alert (ajax_return)
}
Don’t use
dataas a variable name. jQuery objects have an object calleddataalready which holds arbitrary data. If you call your variabledat, you should get better results.See http://api.jquery.com/jQuery.data/
A shorter implementation could be to just say
success: receiverwith no parameters, and write your receiver signature asThen data is passed by the jQuery callback.