remote.JSON Class
LudoJS class for remote JSON queries. Remote queries in ludoJS uses a REST-like API where you have resources, arguments, service and data. An example of resource is Person and City. Example of services are "load", "save". Arguments are arguments used when instantiating the resource on the server, example: Person with id 1. The "data" property is used for data which should be sent to the service on the server. Example: For Person with id equals 1, save these data.
Item Index
Methods
Attributes
Methods
getResponse
()
Object | Undefined
Return entire server response of last request.
Returns:
getResponseData
()
Object | Undefined
Return JSON response data from last request.
Returns:
send
-
service
-
resourceArguments
-
serviceArguments
-
additionalData
Send request to the server
Example:
ludo.config.setUrl('/controller.php'); var req = new ludo.remote.JSON({ resource : 'Person' }); req.send('load', 1);
Will trigger the following data to be sent to controller.php:
{
request:"Person/1/load"
}
If you have the mod_rewrite module enabled and activated on your web server, you may use code like this:
ludo.config.enableModRewriteUrls();
ludo.config.setDocumentRoot('/'); var req = new ludo.remote.JSON({ resource : 'Person' }); req.send('load', 1);
which will send a request to the following url:
:
http://
Here's another example for saving data(mod rewrite deactivated)
ludo.config.setUrl('/controller.php');
var req = new ludo.remote.JSON({
resource : 'Person'
}); req.send('save', 1, { "firstname": "John", "lastname": "Johnson" });
which will send the following POST data to "controller.php":
{ "request": "Person/1/save", "data": { "firstname": "John", "lastname": McCarthy" } } When mod_rewrite is enabled, the request will be sent to the url /Person/1/save and POST data will contain
{ "data": { "firstname": "John", "lastname": "McCarthy" } } i.e. without any "request" data in the post variable since it's already defined in the url.