https://github.com/toddself/jsonpject
Provide a JSONP callback if necessary on a remote loaded script
https://github.com/toddself/jsonpject
Last synced: 2 months ago
JSON representation
Provide a JSONP callback if necessary on a remote loaded script
- Host: GitHub
- URL: https://github.com/toddself/jsonpject
- Owner: toddself
- License: mit
- Created: 2013-08-09T16:04:02.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-05-15T20:08:34.000Z (about 12 years ago)
- Last Synced: 2025-03-14T20:03:22.735Z (over 1 year ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 1
- Watchers: 13
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](http://travis-ci.org/toddself/jsonpject)
# JSONPject
Takes a JSONP script (one that has a callback=) in the query string and a callback and provides a new script URL specifiying a new callback which wraps the passed in callback. The included script will call the provided callback, ensuring your callback is only called when the JSONP script has finished loading.
# Usage
This sort of assumes you're using something to let you use CommonJS modules on the browser end.
```javascript
var jsonpject = require('jsonpject');
function my_callback(data){
do_something_with(data);
}
var jsonp = jsonpject('http://test.com/a_script.js?callback=?');
window[jsonp.fn_name] = jsonp.fn;
var scr = document.createElement('script');
scr.src = jsonp.url;
document.head.appendChild(scr);
```
# Testing
Uses grunt to do testing. Test is available from npm
`npm install`
`npm test`
# License
JSONPject is provided under the terms of the [MIT License](/LICENSE)
Copyright 2013 Condé Nast