Posts

Showing posts with the label JSONP

How To JSONP A Static File

Update I have discussed this object a part and I agree that the url could be used as unique id as well. In this case the server should use the static url as unique id: StaticJSONP.notify("http://cdn.com/static/article/id.js",{..data..}); So that on client side we can use the simplified signature: StaticJSONP.request( "http://cdn.com/static/article/id.js", function (uid, data) { } ); The callback will receive the uid in any case so that we can create a single callback and handle behaviors accordingly. The script has been updated in order to accept 2 arguments but, if necessary, the explicit unique id is still supported. Under the list of " incomplete and never posted stuff " I found this article which has been eventually reviewed. I know it's " not that compact " but I really would like you to follow the reason I thought about a solution to a not so common, but quite nasty, problem. Back in 2001, my early attempts to include cal...

All You Need for JSONP

I have just uploaded a truly simple, still robust, function able to do generic JSONP without pretending too much magic. The concept is simple, we pass the url, including the parameter name used to communicate the callback name, and a callback as second argument ... that's it, 202 216 bytes minified and gzipped ( many thanks @jdalton for the catch ) Here an example: <!-- the generic HTML page --> <script src="JSONP.js"></script> <script> this.onload = function () { var many = 0; JSONP("test.php?callback", function (a, b, c) { this.document.body.innerHTML += [ a, b, ++many, c ].join(" ") + "<br />"; }); JSONP("test.php?callback", function (a, b, c) { this.document.body.innerHTML += [ a, b, ++many, c ].join(" ") + "<br />"; }); }; </script> And here the testable demo result that should work with every bloody damned browser. What's on the server? No...