JSON-P

JSON-P means JSON with padding.

For security reason, browser rejects JavaScript loading resource from the other sites.

The following version works without security errors of cross-domain accessing resources.

1;(function($){
2  $.getJSON('http://api.openweathermap.org/data/2.5/weather?q=Macao,MO&callback=?', function(data){
3    console.log(data);
4  });
5}).call(this, jQuery);

The callback=? is to tell jQuery getJSON method to use the JSON-P approach instead of cross-domain JSON loading. For security reason, browser rejects JavaScript loading resource from the other sites (domains other than where the JavaScript is executed). Either enabling cross-domain resourcing sharing in server or allowing the JSON-P in server can by pass this security restriction.

What’s next? We’re going to take a look at “Preparing graphics”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content