Do you remember my good old wru project? It has been refactored, readapted for both client and server side environment such node.js and Rhino and, most important, it landed in github ;)
Please spend few minutes to read the documentation and you'll realize why I chose this title for this post.
Have fun with JavaScript Unit Tests!
behind the design
My JavaScript book is out!
Don't miss the opportunity to upgrade your beginner or average dev skills.
Showing posts with label essential. Show all posts
Showing posts with label essential. Show all posts
Sunday, August 21, 2011
Wednesday, February 16, 2011
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:
And here the testable demo result that should work with every bloody damned browser.
What's on the server? Nothing more than this:
Enjoy ;)
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,
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? Nothing more than this:
<?php
if (isset($_GET['callback'])) {
header('Content-Type: application/javascript');
exit($_GET['callback'].'.call(window, "Hello", "JSONP", "!!!")');
}
?>
Enjoy ;)
Subscribe to:
Posts (Atom)