GitXplorerGitXplorer
w

super-simple-jsonp

public
2 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
d84b2eab8fa5d82e3bd7f14db1f2505ba4e5a239

Adding tests and list of tested browsers. Also updated documentation about error handling.

wwalling committed 14 years ago
Unverified
d2b6efef9759a74e96546930220636476b6cec5a

Better way to remove DOM elements.

wwalling committed 14 years ago
Unverified
c9e2027a97882524c6c9e2b17cefaa3284666596

You have to opt-in to strict mode, which gives more error handling.

wwalling committed 14 years ago
Unverified
d28b2b8675700ac7e400288a787babbcc81daabb

Fix to MSIE does not leak memory.

wwalling committed 14 years ago
Unverified
10a334340f6b8ed810e2f6b18f8136bebc7ea129

Refactoring.

wwalling committed 14 years ago
Unverified
1c22bac98a6dc102b494cbb9e054a2ed80b92530

Making js_modules to make Mud happy.

wwalling committed 14 years ago

README

The README file for this repository.

Super Simple JSONP

This is a super simple implementation of JSONP in client-side JavaScript, which handles errors in an elegant way. Read the below license, which is the closest I get to releasing this software in the public domain.

The file js_modules/jsonp.js is the implementation. Minify it if you want.

The file jsonp-usage-example.html is just an example how to use it to query Flickr for cat pictures with a timeout of 2 seconds.

Happy hacking!

Bjarke Walling

Install

Install it with Mud:

npm install -g mud        # If you haven't already! :-)
mud install jsonp         # Install this JavaScript module
mud server                # Run local server, which enables development

Read more about Mud package manager at http://mudhub.org/.

Usage

Look in the inline documentation or the example to see how you use it. For local development, just start mud server and in your HTML:

<script src="http://mudhub.org/dev"></script>
<script>
  var jsonp = require('jsonp');
  // use it here
</script>

To deploy, use mud inline your.html or to just minify the module:

mud modules jsonp --global --compile > jsonp.min.js

You can also use --compile-advanced for more aggressive optimizations (which I did not test yet). The minifier is Closure. Read more at the Mud website.

Error handling

If the connection fails, the URL does not exists or the result is not JSON or non-existing, or the internal JSONP callback was called without any arguments, the request fails with a generic JSONP Request Failed message. If you use strict mode, the request also fails if the result is null and the webservice can signal errors using {"error":"Total Failure"}.

Tested browsers

Open tests.html in your webbrowser to run the tests. Tested browsers:

  • Google Chrome 11.0 for Linux
  • Google Chrome 11.0 for Windows
  • Firefox 3.6 for Linux
  • MS Internet Explorer 6.0 [FAILS, probably in common.step]

License

Permission is granted to use, modify, and / or redistribute at will.

This includes removing authorship notices, re-use of code parts in other software (with or without giving credit), and / or creating a commercial product based on it.

This permission is not revocable by the author.

This software is provided as-is. Use it at your own risk. There is no warranty whatsoever, neither expressed nor implied, and by using this software you accept that the author(s) shall not be held liable for any loss of data, loss of service, or other damages, be they incidental or consequential. Your only option other than accepting this is not to use the software at all.