http://wiki.freedesk.purplepixie.org/w/index.php?title=JS_ServerRequest&feed=atom&action=historyJS ServerRequest - Revision history2024-03-29T08:30:26ZRevision history for this page on the wikiMediaWiki 1.19.0http://wiki.freedesk.purplepixie.org/w/index.php?title=JS_ServerRequest&diff=24&oldid=prevDave: Created page with "= Overview = The ServerRequest Javascript class provides a common AJAX framework for all FreeDESK components. = Example = The following is a commented example to demonstrat..."2012-06-27T23:17:55Z<p>Created page with "= Overview = The ServerRequest Javascript class provides a common AJAX framework for all FreeDESK components. = Example = The following is a commented example to demonstrat..."</p>
<p><b>New page</b></p><div>= Overview =<br />
<br />
The ServerRequest Javascript class provides a common AJAX framework for all FreeDESK components.<br />
<br />
= Example =<br />
<br />
The following is a commented example to demonstrate it's use:<br />
<br />
<source lang="javascript"><br />
function myCallback(xml, additional) // this function deals with our results<br />
{<br />
// do nothing... just an example...<br />
// but here we could process the xml and any additional values passed<br />
}<br />
<br />
// Make a new ServerRequest<br />
var sr = new ServerRequest();<br />
<br />
// Now let's set some options...<br />
sr.xmlrequest = true; // Is it an XML or HTML request (the type of data coming back, the default is XML but we'll set it anyway)<br />
sr.async = true; // Asynchronous or synchronous request (default is async but will set again for example)<br />
sr.randomise = true; // Append a random string to a GET request to avoid caching (again default is true)<br />
<br />
// And for the actual call...<br />
sr.url = "somepage.php?opt1=A&opt2=B"; // Our URL including query string<br />
sr.callback = myCallback; // Our callback function<br />
sr.additional[0] = 1; // We can set the additional data which is an Array and will also be passed to myCallback<br />
<br />
// And perform the request...<br />
sr.Get(); // do a Get request as setup<br />
<br />
// This should have done a GET request and then (if no error occured) gone to myCallback with the resultant XML and also the additional data we set.<br />
<br />
// Now for a POST example...<br />
var asr = new ServerRequest();<br />
asr.url = "somepage.php"; // just the page this time no query GET data<br />
var data = "opt1=A&opt2=B"; // our URI-encoded data for the POST<br />
asr.callback = myCallback;<br />
asr.additional[0] = 1;<br />
<br />
// All setup now the POST<br />
asr.Post(data); // pass the URI encoded data<br />
<br />
// And again we should go back to myCallback the same as before<br />
</source></div>Dave