jsonp.js

Creates a Json request using a script tag include and handles the callbacks for you.

Dependencies

MootoolsMoo.js, Array.js, String.js, Function.js, Utility.js, Element.js, Common.js

Author

Aaron Newton <aaron [dot] newton [at] cnet [dot] com>

Summary
jsonp.jsCreates a Json request using a script tag include and handles the callbacks for you.
JsonPCreates a Json request using a script tag include and handles the callbacks for you.
Properties
requestExecutes 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.

JsonP

Creates a Json request using a script tag include and handles the callbacks for you.

Arguments

urlthe url to get the json data
optionsan object with key/value options

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

Example

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();

The above example would generate this url

(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.

Summary
Properties
requestExecutes the Json request.

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.

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

My Object Oriented javascript.
function $A(array,
start,
length)
returns a copy of the array.
Same as Array.copy, but as function.
function $each(iterable,
fn,
bind)
Use to iterate through iterables that are not regular arrays, such as builtin getElementsByTagName calls, arguments of a function, or an object.
Contains Array prototypes, $A, $each
Contains String prototypes and Number prototypes.
Contains Function prototypes and utility functions .
Contains Utility functions
function $(el)
returns the element passed in with all the Element prototypes applied.
Contains useful Element prototypes, to be used with the dollar function $.
Contains common implementations for custom classes.