...

View Full Version : jsonp



sybil6
03-09-2009, 07:52 PM
can someone give me a code example of jsonp ready to be used?

TinyScript
03-12-2009, 07:45 PM
I think this is what you're looking for.
http://www.geocities.jp/stormriders999/jsontest.html

sybil6
03-13-2009, 06:41 PM
thanks heres another one:
http://linked.drag2web.com/crossdomain/

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

rnd me
03-14-2009, 03:20 AM
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.

sybil6
03-14-2009, 11:08 AM
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.

rnd me
03-15-2009, 12:31 AM
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})

sybil6
03-16-2009, 02:22 PM
could you help me here to get this simple example working?
here is my Js client side:


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:

({ "items": [

{ "firstName" : "John",
"lastName" : "Doe",
"age" : 23 }
]
})

rnd me
03-17-2009, 08:29 AM
function processJSON(data){
alert(data.items.firstName)

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum