Skip to content

Instantly share code, notes, and snippets.

@kassens
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>
<extends>Request</extends>
<syntax>var myJSONRemote = new Request.JSON([options]);</syntax>
<arguments>
<argument name="options" type="object" optional="true">See below.</argument>
</arguments>
<options>
<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" />)
</option>
</options>
<events>
<event name="success">
...
</event>
</events>
<example>
<description>
This code will send a data object via a GET request and alert the retrieved data.
</description>
<code type="javascript">
var jsonRequest = new Request.JSON({url: "http://site.com/tellMeAge.php", 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'});
</code>
</example>
<method name="setHeader">
<description>
Add or modify a header for the request. It will not override headers from the options.
</description>
<syntax>myRequest.setHeader(name, value);</syntax>
<arguments>
<argument name="name" type="string">The name for the header.</argument>
<argument name="value" type="string">The value to be assigned.</argument>
</arguments>
<return type="object">This Request instance.</return>
<example>
<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');
</code>
</example>
</method>
</class>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment