Ajax

From NSB App Studio
Revision as of 13:24, 22 June 2012 by Brendon (talk | contribs) (Created page with "AJAX(''URL[,method[,data,[returnFunction]]]'') '''Description''' The AJAX function is used to get or receive data from a server. It is based on XMLHttpRequest. This function...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

AJAX(URL[,method[,data,[returnFunction]]])

Description

The AJAX function is used to get or receive data from a server. It is based on XMLHttpRequest. This function will only work when deployed to the website: it will not work when running in the local browser.

URL is the address on the server. It can be the name of a file to be downloaded from the server or a script to be run on the server. Optional information can be passed to the server at the end of the URL: for example http://www.nsbasic.com/getCustomerInfo.php?customer=Knuth will call the PHP script named getCustomerInfo.php, passing the parameter customor=Kruth.

Use method to define the access method. If this parameter is omitted, GET is used. The most common value for this is POST. POST responses are never cached, whereas GET responses can be. POST also allows larger data transfers. If you are using POST, put the information you want to send in data. The normal size limit for data is 8 megabytes: it is a server setting which can be increased. This is an easy and efficient way to send data to a server.

returnFunction, if supplied, is a function to be called when the results return, allowing asynchronous execution. If this parameter is not supplied, execution will continue at the next statement after the results return.

Other methods are CONNECT, DELETE, HEAD, OPTIONS, PUT, TRACE, or TRACK. For more information on these options, look up XMLHttpRequest on the web.

It returns two values: If .status = 0 or 200, the call was successful. Any data that is returned will be in .responseText. If the file is not read successfully, a status code is returned in .status.

See also samples Ajax and AjaxPost for more information.


Example

REM AJAX example
req=Ajax("/sendData_ajax.php/?myText=" + txtSend.value) 
If req.status=200 Then 'success
    txtResponse.value=req.responseText
  Else 'failure
    txtResponse.value="Error: " & req.err.message
End If

'Sample POST call
req=Ajax("/sendData_ajaxPost.php","POST",txtSend.value)

Related Items

READFILE