A "JSONP server" should accept a GET argument that is usually named "jsoncallback".
The format of the returned text should look like a call to a function with a JSON object passed as argument, the name of the function that will be called is defined by the jsoncallback GET argument, if it is a question mark the name of the function should be empty. To stay on the safe side, please return a HTTP header with this content type: "application/x-javascript"
As an example see the Flickr JSONP service, which allows to fetch images from Flickr with javascript.
I have thought of two possible formats, I'll let you choose which you want to use:
Format 1:
Use this format if you want to "force" the requesting website to use your HTML formatting. I say "force" because with jQuery it is way too easy to manipulate HTML and exclude parts of the received text.
If I make this GET request: http://http://www.openuru.org/tools/cav ... rseOpenUru
and MOULa is open, I should get the following response:
Code: Select all
parseOpenUru({'widgetHTML':'<div id="cspanel"><span class="cshead">Cavern Status:</span><img src="http://www.openuru.org/sitestyle/img/led-green.gif" /> Open for exploration! <div id="cavstat_link"> - <a href="http://mystonline.com/play/"> Sign up to play at MystOnline.com!</a></div><div id="cavstat_row2"><span class="cshead">Developer Message:</span> Welcome to Myst Online: Uru Live!</div><div style="font-size: 8px; text-align: right;"><a href="http://www.openuru.org/">OpenUru.org</a></div></div>'})
Format 2:
In this format you give complete freedom to the requesting website to choose which parts they want and which HTML format they want to use. Here you only provide information and leave it up to the webdesigner to choose an HTML structure to put it in. This is extremely flexible to give people the freedom to format the widget in any way they want.
Code: Select all
parseOpenUru({'statusImg':'http://www.openuru.org/sitestyle/img/led-green.gif', 'statusText':'Open for exploration!','moulLink':'http://mystonline.com/play/','moulText':'Sign up to play at MystOnline.com!','devMsg':'Welcome to Myst Online: Uru Live!','providerLink':'http://www.openuru.org/','providerName':'OpenUru.org'})
If you use this second format you can also rewrite the PHP code to use it, because PHP has the json_decode function that accepts a JSON formatted string and returns an associative array containing all the members of the JSON object. This way the PHP code will be completely HTML independent too.
Or you could even use a merge of the two formats (i.e. add the 'widgetHTML' member to the format 2 JSON object), so who wants to use their format for the widget they can do it, and the lazy webdesigner can just pick the whole HTML and put it in his webpage.
^^
EDIT: I'm sorry I didn't see the edit to you message MacFife. Yes your example is exactly what I need XD