3 questions about JSON-P format.

Posted by Tristan on Stack Overflow See other posts from Stack Overflow or by Tristan
Published on 2010-04-18T18:18:55Z Indexed on 2010/04/18 18:23 UTC
Read the original article Hit count: 204

Filed under:
|
|
|

Hi,

I have to write a script which will be hosted on differents domains. This script has to get information from my server.

So, stackoverflow's user told me that i have to use JSON-P format, which, after research, is what i'm going to do. (the data provided in JSON-P is for displaying some information hosted on my server on other website)

  1. How do I output JSON-P from my server ? Is it the same as the json_encode function from PHP

  2. How do i design the tree pattern for the output JSON-P (you know, like : ({"name" : "foo", "id" : "xxxxx", "blog" : "http://xxxxxx.com"}); can I steal this from my XML output ? (http://bit.ly/9kzBDP)

  3. Each time a visitor browse a website on which my widget is it'll make a request on my server, requesting the JSON-P data to display on the client side. It'll increase dramatically the CPU load (1 visitor on the website who will have the script = 1 SQL request on my server to output data), so is there any way to 'caching' the JSON-P information output to refresh it only one or twice a day and stores it into a 'file' (in which extension?).

BUT on the other hand i would say that requesting the JSON-P data directly (without caching it) is a plus, because, websites which will integrates the script only want to display THEIR information and not the whole data. So, making a script with something like that:

jQuery.getJSON("http://www.something.com/json-p/outpout?filter=5&callback=?", function(data) {
................);
});

Where filter= the information the website wants to display

What do you think ?

Thank you very much ;)

© Stack Overflow or respective owner

Related posts about jsonp

Related posts about crossdomain