I want to make an Ajax call from different .js file. I did something like this:
function ajax(url,success,error)
{
success+="(data)";
error+="(xhr, ajaxOptions, thrownError)";
console.log("Starting AJAX");
console.log("Success function: " + success);
console.log("Success function: " + error);
$.ajax({
crossDomain: true,
type: 'GET',
url: url,
callback: 'jsonpCallback',
jsonpCallback: 'jsonpCallback',
jsonp: '_jsonp',
scriptCharset: "utf-8",
contentType: 'application/json',
dataType: 'jsonp json',
timeout : 5000,
success: success_contact(data),
error: error_contact(),
});
}
There are also functions success_contact and error contact. I started it like this:
$(document).bind('pageinit', function() {
ajax('http://topfirma-dev/topfirma-www/services/rest/contact/list','success_contact','error_contact');
});
Ajax call is called, but there is an error:
Uncaught ReferenceError: data is not defined
And here is my question. How can I catch data from my Ajax call?
If
success_contactanderror_contactare defined elsewhere, you do not need to call them as functions there, you just tell which functions they are.