SUI.xhr

Holds a set of xhr related functions.

Defined in: xhr.js


Method summary

Attr. Type Name / Description
public

doGet(url, data, callback)

Execute a get request to an http server and supply a callback function to deal with the response.

public

doPost(url, data, callback)

Execute a post request to an http server and supply a callback function to deal with the response.

public Object

queryString(data)

Convert a javascript object to an url query string. The data will be url-encoded. The function does not support rescursive structures (no inner objects) but it supports 1D array values for the members of the argument object. Note that this function is designed to work with PHP and that arrays will be converted to the "name[]" syntax that (afaik) only PHP supports. For example: { a: "V&D", b: [1, 2] } will be translated to "a=V%26D&b[]=1&b[]=2".

public Object[]

tableToObjArr(t)

Convert tabelized data to an array of objects. When sending a json string containing an huge array of objects you might want to consider to send the data in a table format: nn array of values only in which the first row defines the field names of the data that follows. For example:

[
  { id: 1, name: "Jan" },
  { id: 2, name: "Piet" },
  { id: 3, name: "Klaas" },
  ...
]

Can also be presended as:

[
  ["id", "name"],
  [1, "Jan"],
  [2, "Piet"],
  [3, "Klaas"],
  ...
]

This function converts the latter to the former.

 


Methods

public doGet( String url, Object data, Function callback)

Execute a get request to an http server and supply a callback function to deal with the response.

Parameters:

Name Type Description
String url The url of an xhr script on a web server.
Object data An object of which the members and their values will be converted to an url query string and appended to the url. Note: it is also possible to add a query string directly to the url parameter, but then you should pass null for this parameter.
Function callback A function with signature ({Object}) to handle the server's response.
public doPost( String url, Object data, Function callback)

Execute a post request to an http server and supply a callback function to deal with the response.

Parameters:

Name Type Description
String url The url of an xhr script on a web server.
Object data An object of which the members and their values will be converted to form encoded data and send along with the request.
Function callback A function with signature ({Object}) to handle the server's response.
public Object queryString( Object data)

Convert a javascript object to an url query string. The data will be url-encoded. The function does not support rescursive structures (no inner objects) but it supports 1D array values for the members of the argument object. Note that this function is designed to work with PHP and that arrays will be converted to the "name[]" syntax that (afaik) only PHP supports. For example: { a: "V&D", b: [1, 2] } will be translated to "a=V%26D&b[]=1&b[]=2".

Parameters:

Name Type Description
Object data An object with name and values pairs to convert to an url query string.

Returns:

Object data An url query string containing the given name and value pairs.

public Object[] tableToObjArr( Array[] t)

Convert tabelized data to an array of objects. When sending a json string containing an huge array of objects you might want to consider to send the data in a table format: nn array of values only in which the first row defines the field names of the data that follows. For example:

[
  { id: 1, name: "Jan" },
  { id: 2, name: "Piet" },
  { id: 3, name: "Klaas" },
  ...
]

Can also be presended as:

[
  ["id", "name"],
  [1, "Jan"],
  [2, "Piet"],
  [3, "Klaas"],
  ...
]

This function converts the latter to the former.

Parameters:

Name Type Description
Array[] t A table of values in which the first row defines the names of the columns.

Returns:

Object[] An array of objects containing name and value pairs.