Difference between JSON and JSONP

Answer

Full Form of JSON
JavaScript Object Notation

Full Form of JSONP

JavaScript Object Notation with Padding.


Json is stardard format that is human readable used to transmit information from one server to another server.

Jsonp is a json with ability to transmit information to another domain. 


JSONP is JSON with padding, that is, you put a string at the beginning and a pair of parenthesis around it. 


JSON Example

 

1 {"Name""Foo""Id"1234"Rank"7};


JSONP Example - In this you can call a function

1 functionCall({"Name""Foo""Id"1234"Rank"7});





With JSON you can't send request to another domain whereas JSONP is really a simply trick to overcome XMLHttpRequest same domain policy. In JSONP you can send request to a different domain.) 

Demo with JSONP

01         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"type="text/javascript"></script>
02         <script>
03             $(document).ready(function(){
04                 $.ajax({
05                     url: 'http://twitter.com/status/user_timeline/padraicb.json?count=5',
06                     dataType: 'jsonp',
07                     success: function(dataWeGotViaJsonp){
08                         var htmlData = '';
09                         var len = dataWeGotViaJsonp.length;
10                         for(var i=0;i<len;i++){
11                             twitterEntry = dataWeGotViaJsonp[i];
12                             htmlData += '<p>
13 <img src = "' + twitterEntry.user.profile_image_url_https +'"/>' + twitterEntry['text'] + '</p>
14 '
15                         }
16                         $('#MyTwitterFeed').html(htmlData);
17                     }
18                 });
19             })
20         </script>
21         <div id="MyTwitterFeed">
22 </div>

All JSON Questions

Ask your interview questions on json

Write Your comment or Questions if you want the answers on json from json Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---