I'm trying to use jQuery to call some custom API via Ajax/$.getJSON
.
I'm trying to pass a custom value into the Ajax callback method, but that value is not getting passed through and is actually getting overwritten. This is my code:
var locationType = 3;
var url = 'blah blah blah' + '&locationType=' + locationType;
$(#loading_status).show();
$.getJSON(url, null, function(results, locationType) {
searchResults(results, locationType)
});
The value of locationType
BEFORE I call the URL using AJAX is 3
. But after the call returns the data successfully, the value for locationType
is now success
. This is because the method signature of the callback is:
callback(data, textStatus)A callback
function that is executed if the
request succeeds.
How can I pass 1 or more parameters to a callback method?