Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript JSONP Cross Browser Issues

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #41020
    sweetback
    Member

    I am having tons of trouble trying to pull cross-domain json data. It works perfectly when the json is local, but as soon as I try the same code cross domain, it breaks. I must be having issues with JSONP but not sure what it is… can anyone help?

    Here is the JSON Code

    knoxStaff({
    “name”: “John Smith”,
    “age” : “34”,
    “sex”: “male”
    })

    and the javascript is

    $.ajax({
    url: ‘http://knoxyouthgroup.org/example.php’,
    dataType: ‘jsonp’,
    jsonpCallback: ‘knoxStaff’, // specify the callback name if you’re hard-coding it
    success: function(staff){
    document.write(staff.name);// we make a successful JSONP call!
    }
    });

    I left up the json file on the server in case anyone wants to try to pull it successfully. THANKS for anyone’s time in advance, I just can’t crack this one!

    #115642
    TheDoc
    Member

    It has something to do with enabling a callback, but that’s as far as my knowledge goes. Generally you’d include it on the `url` itself: `http://knoxyouthgroup.org/example.php&callback=jsonp`

    That’s a crude example.

    #115670
    sweetback
    Member

    Thanks so much for your response Doc… I tried an example of that route too:

    $.getJSON(“http://www.knoxyouthgroup.org/example.php?callback=?”, function(data) {
    document.write(data.name);// we make a successful JSONP call!
    });

    But that came up empty too. Driving me nuts! Is anyone able to make this work or guide me in the right direction?

    #115766
    SgtLegend
    Member

    I just tried your example link and it worked perfect for me, what browsers are you testing in?

    #115914
    sweetback
    Member

    The link to the data works, but trying the jquery to pull in the data displays nothing… or did that part work for you??? That would be great news, but I am not seeing it here. Have tried Chrome, Firefox and Safari.

    I managed to get rid of all errors on the console, but it just doesn’t display the data. The document.write function does not seem to be doing anything, just a blank page.

    Thanks for your help SgtLegend, would really love to figure this out!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.