I’m just wondering if there’s a point to having a callback function on success in jQuery’s getJSON function if I’m using JSONP.
From the documentation:
http://api.jquery.com/jQuery.getJSON/
jQuery.getJSON( url [, data] [, success(data, textStatus, jqXHR)] )
The “success” function is triggered after a successful JSON response.
However, if we use JSONP where the function callback is in the JSONP response, is there a need for the “success” function?
I’m guessing no, but I can’t find any information on the page to confirm it. I just don’t want to overlook some sort of security issue if there is a reason to use the “success” function.
Thanks!
jQuery automatically sets up its own callback function (with an autogenerated name) on the global window object and replaces the “?” in “callback=?” with the function’s name. That callback function calls yours.
This means you can just pass an anonymous function to jQuery instead of having to make sure you don’t use the same function name twice, just as with normal AJAX requests using jQuery.
Relevant quote from jQuery.ajax() documentation: