JS ServerRequest

From FreeDESK
(Difference between revisions)
Jump to: navigation, search
(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...")
 

Latest revision as of 23:17, 27 June 2012

[edit] Overview

The ServerRequest Javascript class provides a common AJAX framework for all FreeDESK components.

[edit] Example

The following is a commented example to demonstrate it's use:

function myCallback(xml, additional) // this function deals with our results
{
 // do nothing... just an example...
 // but here we could process the xml and any additional values passed
}
 
// Make a new ServerRequest
var sr = new ServerRequest();
 
// Now let's set some options...
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)
sr.async = true; // Asynchronous or synchronous request (default is async but will set again for example)
sr.randomise = true; // Append a random string to a GET request to avoid caching (again default is true)
 
// And for the actual call...
sr.url = "somepage.php?opt1=A&opt2=B"; // Our URL including query string
sr.callback = myCallback; // Our callback function
sr.additional[0] = 1; // We can set the additional data which is an Array and will also be passed to myCallback
 
// And perform the request...
sr.Get(); // do a Get request as setup
 
// 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.
 
// Now for a POST example...
var asr = new ServerRequest();
asr.url = "somepage.php"; // just the page this time no query GET data
var data = "opt1=A&opt2=B"; // our URI-encoded data for the POST
asr.callback = myCallback;
asr.additional[0] = 1;
 
// All setup now the POST
asr.Post(data); // pass the URI encoded data
 
// And again we should go back to myCallback the same as before
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox