vegui. bridge. class.js

Summary
allows you do specify which domain to use for all requests sent with the bridge, default: ‘’
VegUI xml request object
constructor
private function
This function will be called on successful response to request if the VegUIRequest’s pFunc property is not set.
Spawns a new XMLHttpRequest object and returns it in the form of a VegUIRequest object
triggered when the maximum number of timeouts is reched
triggered everytime a request times out, submits the timed out request as a parameter
Polls the Request array for any timed out requests and handles them arcordingly.
When a request gets a response from the server then it will go through this function where it will determine if it was a successful request or not
send a request to the server
private function

Constants

VUI_URL

allows you do specify which domain to use for all requests sent with the bridge, default: ‘’

VegUIRequest

VegUI xml request object

Properties

Object Properties

timeCreationint, time of creation
timeSendint, time it took to send and get a request
requestXMLHttpRequest, the xml http request object
toElementVegUIElement, request belongs to this element
processfunction, if set this function will be executed when the request has been responded to by the server
idint, unique request id

Functions

VegUIRequest

function VegUIRequest(req,
id,
toElement)

constructor

Parameters

XMLHttpRequest reqthe xml http request object
int idthe unique request id
<VegUIElement toElement>flags this request as belong to the submitted element

VegUIBridge

Allows clientserver communication
Summary
private function
This function will be called on successful response to request if the VegUIRequest’s pFunc property is not set.
Spawns a new XMLHttpRequest object and returns it in the form of a VegUIRequest object
triggered when the maximum number of timeouts is reched
triggered everytime a request times out, submits the timed out request as a parameter
Polls the Request array for any timed out requests and handles them arcordingly.
When a request gets a response from the server then it will go through this function where it will determine if it was a successful request or not
send a request to the server
private function

Properties

Object Properties

maxSendTimeint, maximum time a request can take before timing out
maxTimeoutsint, maximum number of timeouts before onmaxtimeouts is called
conTimeoutsint, current timeouts in a row
sendNumint, number of requests sent
timeoutNumint, total number of timeouts
successNumint, total number of successful requests
PTimerInterval, the interval object that polls timeouts
denyRequests*bool’, if true no requests can be sent
resendbool, if true failed requests will be resent
Request, RArray, holds all active requests

Functions

cleanup

this.cleanup = function(vreq)

private function

Removes a request from the list

Parameters

VegUIRequest vreqrequest to be removed

execute

this.execute = function(vreq)

This function will be called on successful response to request if the VegUIRequest’s pFunc property is not set.  Be aware that you may overwrite the execute methid with your own by simply redefining it

This is useful if you decide to create a network protocol.  All server responses will be sent to this function and can be processed accordingly.

dummy function

Parameters

VegUIRequest vreqthe request that was successful

Returns

booltrue

Examples

Bridge.execute = function(vreq) {
alert(vreq.request.responseText);
};
Bridge.send('some_file.txt');

new_request

this.new_request = function(toElement)

Spawns a new XMLHttpRequest object and returns it in the form of a VegUIRequest object

private function

Parameters

<VegUIElement toElement>if set the request will be flagged to belong to the submitted element

onmaxtimeouts

triggered when the maximum number of timeouts is reched

ontimeout

triggered everytime a request times out, submits the timed out request as a parameter

poll_timeouts

this.poll_timeouts = function()

Polls the Request array for any timed out requests and handles them arcordingly.  May call onmaxtimeouts and ontimeout

private function

process_request

this.process_request = function(vreq)

When a request gets a response from the server then it will go through this function where it will determine if it was a successful request or not

private function

Parameters

VegUIRequest vreqthe request object

send

this.send = function(url,
para,
method,
pFunc,
sync)

send a request to the server

Parameters

string urlurl or relative path to send the request to
<string para>url parameter string
<string method>method to use
<function pFunc>custom process function that will be executed when the request was returned successfully
<bool sync>if true the request will be synchronous to the execution of the script, false by default.

See also

<process>

Example

// requests the file some_file.php and submits the argument
// string as GET variables. The response of this request
// will be processed by the Bridge.execute function

Bridge.send('some_file.php', 'name=jon&age=13', 'GET');

// same as above only that it will be a POST request

Bridge.send('some_file.php', 'name=jon&age=13', 'POST');

// in this case the response of the server will not be handled
// by Bridge.execute, but by the function that is submitted.
// the function will be a property of the created vreq object
// and therefor 'this' will point to the vrew object.

Bridge.send('some_file.php', 'name=jon&age=13', 'GET',
function() {
alert(this.request.responseText);
}
);

valid_id

this.valid_id = function()

private function

Returns

intvalid request id
function VegUIRequest(req,
id,
toElement)
constructor
this.cleanup = function(vreq)
private function
this.execute = function(vreq)
This function will be called on successful response to request if the VegUIRequest’s pFunc property is not set.
VegUI xml request object
this.new_request = function(toElement)
Spawns a new XMLHttpRequest object and returns it in the form of a VegUIRequest object
this.poll_timeouts = function()
Polls the Request array for any timed out requests and handles them arcordingly.
this.process_request = function(vreq)
When a request gets a response from the server then it will go through this function where it will determine if it was a successful request or not
this.send = function(url,
para,
method,
pFunc,
sync)
send a request to the server
this.valid_id = function()
private function
triggered when the maximum number of timeouts is reched
triggered everytime a request times out, submits the timed out request as a parameter