Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: jsonp

  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts

    jsonp

    can someone give me a code example of jsonp ready to be used?

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    I think this is what you're looking for.
    http://www.geocities.jp/stormriders999/jsontest.html

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    thanks heres another one:
    http://linked.drag2web.com/crossdomain/

    i am still trying to master this jsonp thingy but havent got it yet.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,413
    Thanks
    11
    Thanked 595 Times in 575 Posts
    the tmpl8 link in my signature contains about a dozen jsonp examples...

    using the tmpl8 function, you might not even have to write any javascript to use a jsonp data source.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #5
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    thank you, a question: does the callback function always need to be on the server side? i am trying to put a very simple example but with no success.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,413
    Thanks
    11
    Thanked 595 Times in 575 Posts
    the call back function is always on the client, in javascript.

    the server only knows the name of the function, adding it into the response so that when the JSON data hits the script tag, the callback function is invoked, and passed the JSON data.

    sample simple server resonse
    JSON:
    ({"A":1, "B":2})

    JSONP:
    alert({"A":1, "B":2})
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #7
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    could you help me here to get this simple example working?
    here is my Js client side:

    Code:
     function loadJSON(url) {
      var headID = document.getElementsByTagName("head")[0];
      var newScript = document.createElement('script');
          newScript.type = 'text/javascript';
          newScript.src = url;
      headID.appendChild(newScript);
    
    }
    
    function processJSON(){
      alert(items.firstName)
    
    }
    
    window.onload=function(){
    loadJSON('http:www.myexample.com/jsonfile.json?format=JSON&callback=processJSON');
             }
    and here is my jsonfile.json on the server side:
    Code:
    ({ "items": [
    
                         { "firstName" : "John",
                        "lastName"  : "Doe",
                        "age"       : 23 }
                        ]
                        })
    Last edited by sybil6; 03-16-2009 at 01:25 PM.

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,413
    Thanks
    11
    Thanked 595 Times in 575 Posts
    Code:
    function processJSON(data){
      alert(data.items.firstName)
    
    }
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • Users who have thanked rnd me for this post:

    sybil6 (03-17-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •