Creates a Json request using a script tag include and handles the callbacks for you.
| Mootools | Moo.js, Array.js, String.js, Function.js, Utility.js, Element.js, Common.js |
Aaron Newton <aaron [dot] newton [at] cnet [dot] com>
| jsonp.js | Creates a Json request using a script tag include and handles the callbacks for you. |
| JsonP | Creates a Json request using a script tag include and handles the callbacks for you. |
| Properties | |
| request | Executes the Json request. |
| Change Log | $Source: /cvs/main/flatfile/html/rb/js/global/cnet.global.framework/common/utilities/jsonp.js,v $ $Log: jsonp.js,v $ Revision 1.5 2007/06/21 17:44:04 newtona fixed a typo; same line was duplicated and I removed the errant one. |
Creates a Json request using a script tag include and handles the callbacks for you.
| url | the url to get the json data |
| options | an object with key/value options |
| onComplete | (optional) function to execute when the data returns; it will be passed the data |
| callBackKey | (string) the key in the url that the server uses to wrap the Json results. So, for example, if you used “callBackKey: ‘callback’” then the server is expecting something like http://....- /?q=search+term- &callback=myFunction defaults to “callback”. This must be defined correctly. |
| queryString | (string, optional) additional query string values to append to the url |
| data | (object, optional) additional key/value data to append to the url |
new JsonP('http://api.cnet.com/restApi/v1.0/techProductSearch', {
data: {
partTag: 'mtvo',
iod: 'hlPrice',
iewType: 'json',
results: '100',
query: 'ipod'
},
onComplete: myFunction.bind(someObject)
}).request();(start code) http://api.cnet.com- /restApi- /v1.0- /techProductSearch?partTag=mtvo- &iod=hlPrice- &viewType=json- &results=100- &query=ipod- &callback=JsonP.requestors[0].handleResults& (end)
It would embed this script tag (in the head of the document) and, when it loaded, execute the “myFunction” callback defined.
| Properties | |
| request | Executes the Json request. |
$Source: /cvs/main/flatfile/html/rb/js/global/cnet.global.framework/common/utilities/jsonp.js,v $ $Log: jsonp.js,v $ Revision 1.5 2007/06/21 17:44:04 newtona fixed a typo; same line was duplicated and I removed the errant one.
Revision 1.4 2007/03/05 19:30:46 newtona added a short (50ms) delay for IE
Revision 1.3 2007/02/27 21:46:43 newtona docs update; fixing references
Revision 1.2 2007/02/22 23:58:33 newtona fixed a bug with the queryString option
Revision 1.1 2007/02/21 00:30:59 newtona first commit
function $A( array, start, length )
Use to iterate through iterables that are not regular arrays, such as builtin getElementsByTagName calls, arguments of a function, or an object.
function $each( iterable, fn, bind )
returns the element passed in with all the Element prototypes applied.
function $( el )