Home › Forums › JavaScript › JSONP Cross Browser Issues
- This topic is empty.
-
AuthorPosts
-
November 27, 2012 at 12:18 pm #41020sweetbackMember
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!
November 27, 2012 at 1:22 pm #115642TheDocMemberIt 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.
November 27, 2012 at 3:56 pm #115670sweetbackMemberThanks 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?
November 29, 2012 at 1:09 am #115766SgtLegendMemberI just tried your example link and it worked perfect for me, what browsers are you testing in?
November 29, 2012 at 9:09 am #115914sweetbackMemberThe 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!
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.