Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Phone API Reference - Classes - NetRequest

NetRequest

Makes HTTP and similar requests from JavaScript. This object is similar to the standard browser XMLHttpRequest object.

Class Constructor

new NetRequest()

Constructs a new NetRequest Object.

var request = new NetRequest();

Initialization Parameters

None

Methods

Name 

Description 

getResponseHeader

Returns the header field value from the response of which the field name matches header, unless the field name is Set-Cookie or Set-Cookie2. Returns null if either the response has not yet been received or the header doesn't exist in the response. 

open

Sets the request method and request URL. This method differs from the standard XMLHttpRequest's open() method by only accepting two parameters (all requests are asynchronous, and the user/password are entered in the request object's user and password properties.)

send

Initiates the request. The optional argument provides the request entity body. The argument is ignored if request method is GET or HEAD.

setRequestHeader

Appends a header to the list of author request headers, or if header is already in the list of author request headers, combines its value with value.

setTimeout

Sets a timeout, after which the request will be aborted with a 500 status. 

Properties

Name 

Description 

oncomplete

Called at the end of the response. This is redundant to onreadystatechange with readyState=4.

Basic Example:

request.oncomplete = function() { util.debug('request is done'); } 

onreadystatechange

Event handler for readyState.

Basic Example:

request.onreadystatechange = function () {
     util.debug(request.readyState);
     util.debug(request.status);
}

password

Password used in the request, or null if there is no password.

Basic Example:

request.password = 'secret'; 

readyState

Returns the current state.

Basic Example:

 var currentState = request.readyState; // returns integer such as 200

responseFile

If present, along with responseLoc, the response body is placed in the file rather than in responseText.

Basic Example:

request.responseFile = "text.txt"; 

responseLoc

If present, along with responseFile, the response body is placed in the file rather than in responseText.

Basic Example:

request.responseLoc = "tmp";

responseText

Returns the text response entity body.

Basic Example:

var response = request.responseText; 

status

Returns the HTTP status code; such as 200 (success), 500 (internal server error), 404 (file not found), etc..

Basic Example:

var statusCode = request.status; 

user

Returns the name of the user in the request, or null if there is no username. Sets the user for the request.

Basic Example:

request.user = "username"; //set username for request
request.user; //"username"

  • No labels