I'm creating an iOS / Droid app using AJAX, jQuery, and Phonegap. The backend is a Drupal 7 site serving content via web services. I'm a little confused about the necessity for a JSONP callback, though.
My understanding is that JSONP is required in order to allow cross domain requests. And, in part, it works by wrapping the JSON data within a callback function, thus making it an object.
However, what I'm finding is that I can send the JSONP request without a callback, and parse the data via jQuery without the callback function. So the JSONP data looks exactly like JSON data.
Am I missing something? If providing the data as function is one of the benefits of JSONP, shouldn't it be required at some stage in the process? Am I bypassing some level of security by not sending a callback parameter?
Thanks!
FYI, here is the jQuery AJAX code:
$.ajax({
type: 'GET',
cache: false,
url: 'http://www.example.com/mobile/menu/devel-gosto.jsonp',
dataType: 'jsonp',
timeout: menuLoadTimeout,
success: function (data) {
menu = populateSlider(data.tree, 0);
}
});
So I'm setting the dataType to 'jsonp', calling to a web service that returns JSONP data, but leaving the callback out of the URL. The web service responds without a callback wrapper. And everything works fine.