Skip to content

Instantly share code, notes, and snippets.

Created June 21, 2009 23:34
Show Gist options
  • Save kassens/133711 to your computer and use it in GitHub Desktop.
Save kassens/133711 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<class name="Request.JSON">
<description>Wrapped Request with automated sending and receiving of JavaScript Objects in JSON Format.</description>
<syntax>var myJSONRemote = new Request.JSON([options]);</syntax>
<argument name="options" type="object" optional="true">See below.</argument>
<option name="secure" type="boolean" default="true">
If set to true, a syntax check will be done on the result JSON (see <link class="JSON" method="decode" />)
<event name="success">
This code will send a data object via a GET request and alert the retrieved data.
<code type="javascript">
var jsonRequest = new Request.JSON({url: "", onComplete: function(person){
alert(person.age); //Alerts "25 years".
alert(person.height); //Alerts "170 cm".
alert(person.weight); //Alerts "120 kg".
}}).get({'firstName': 'John', 'lastName': 'Doe'});
<method name="setHeader">
Add or modify a header for the request. It will not override headers from the options.
<syntax>myRequest.setHeader(name, value);</syntax>
<argument name="name" type="string">The name for the header.</argument>
<argument name="value" type="string">The value to be assigned.</argument>
<return type="object">This Request instance.</return>
<code type="javascript">
var myRequest = new Request({url: 'getData.php', method: 'get', headers: {'X-Request': 'JSON'}});
myRequest.setHeader('Last-Modified','Sat, 1 Jan 2005 05:00:00 GMT');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment