API Docs for: 0.0.2
Show:

remote.JSON Class

Extends Events
Module: language

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.

Methods

getResponse

() Object | Undefined

Return entire server response of last request.

Returns:

Object | Undefined:

getResponseData

() Object | Undefined

Return JSON response data from last request.

Returns:

Object | Undefined:

send

(
  • service
  • resourceArguments
  • serviceArguments
  • additionalData
)

Send request to the server

Parameters:

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:///Person/1/load The query will not contain any POST data.

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.

setResource

(
  • resource
)

Set name of resource

Parameters:

Attributes

resource

String

Name of resource to request, example: "Person"

url!~YUIDOC_LINE~!optional

String

Optional url to use for the query instead of global set url.