Sign in

.getHttp()

Performs an HTTP request to the server.

Syntax

neon.getHttp(string url, function callback 
[, string method [, body [, string contenttype]]]);

url

The URL of the resource to request.

callback

The function to be called when the resource has been fetched.

method

The HTTP request method to use. The default is "GET".

body

This argument may contain a string containing the body to sent in the request (for example, in a POST request).

Alternatively, this argument may contain an object of key: value pairs to be sent as application/x-www-form-urlencoded keys and values, similar to submitting a form by the POST method.

Return value

This method has no return value. It was decided not to make this method chainable to prevent potential confusion, since the method accepts a function that is not executed immediately.

Description

This method provides simple AJAX functionality in Neon. The request is made asynchronously, and relies on a callback function which will be called when the request completes.

In case of failure, the callback function may never be called. If you would like to detect a failure case, you may need to implement your own timeout mechanism.

Using the callback function

The callback function will be passed an XMLHttpRequest object as its parameter, allowing the function to look up information about the response from the server. The format of this object is fairly uniform across all browsers, and is specified elsewhere. The following list is only a short and incomplete list of commonly used properties.

  • string responseText

    The body of the response, from the server, in text format.

  • string responseXML
    

    If the server supplied a valid XML document in response, this property will contain a DOM document object based on the XML that was sent.

  • Number status
    

    The HTTP status returned by the server in the header of its response. This is usually used to indicate whether the request was successful. An example value is 200, which indicates a normal, successful request.