³ÉÈË¿ìÊÖ

Please turn on JavaScript. To find out how to do this visit the .

Sending data to & from the server

Further Info & Examples

Methods

del

Makes an HTTP DELETE request to a given url

Synopsis

glow.net.del(url, opts);

Parameters

url
Type

Url to make the request to. This can be a relative path. You cannot make requests for files on other domains, to do that you must put your data in a javascript file and use glow.net.loadScript to fetch it.

opts
Type

Same options as glow.net.get

Returns

glow.net.Request | glow.net.Response

A response object for non-defered sync requests, otherwise a request object is returned

Example

glow.net.del("myFile.html", {
  onLoad: function(response) {
    alert("Got file:\n\n" + response.text());
  },
  onError: function(response) {
    alert("Error getting file: " + response.statusText());
  }
});
get

Makes an HTTP GET request to a given url

Synopsis

glow.net.get(url, opts);

Parameters

url
Type

Url to make the request to. This can be a relative path. You cannot make requests for files on other domains, to do that you must put your data in a javascript file and use glow.net.loadScript to fetch it.

opts
Type

Options Object of options.

async

Should the request be performed asynchronously?

Type
Default
true
Optional
Yes
defer

Do not send the request straight away

Type
Default
false
Optional
Yes

Deferred requests need to be triggered later using myRequest.send()

forceXml

Treat the response as XML.

Type
Default
false
Optional
Yes

This will allow you to use response.xml() even if the response has a non-XML mime type.

headers

A hash of headers to send along with the request

Type
Optional
Yes

Eg {"Accept-Language": "en-gb"}

onAbort

Callback to execute if the request is aborted

Type
Optional
Yes
onError

Callback to execute if the request was unsucessful

Type
Optional
Yes

The callback is passed a Response object as its first parameter. This callback will also be run if a request times out.

onLoad

Callback to execute when the request has sucessfully loaded

Type
Optional
Yes

The callback is passed a Response object as its first parameter.

timeout

Time to allow for the request in seconds

Type
Optional
Yes

No timeout is set by default. Only applies for async requests. Once the time is reached, the error event will fire with a "408" status code.

useCache

Allow a cached response

Type
Default
false
Optional
Yes

If false, a random number is added to the query string to ensure a fresh version of the file is being fetched

Returns

glow.net.Request | glow.net.Response

A response object for non-defered sync requests, otherwise a request object is returned

Example

var request = glow.net.get("myFile.html", {
  onLoad: function(response) {
    alert("Got file:\n\n" + response.text());
  },
  onError: function(response) {
    alert("Error getting file: " + response.statusText());
  }
});
loadScript

Loads data by adding a script element to the end of the page

Synopsis

glow.net.loadScript(url, opts);

Parameters

url
Type

Url of the script. Use "{callback}" in the querystring as the callback name if the data source supports it, then you can use the options below

opts
Type
Optional
Yes

An object of options to use if "{callback}" is specified in the url.

charset

Charset attribute value for the script

Type
Optional
Yes
onAbort

Called if the request is aborted

Type
Optional
Yes
onError

Called on timeout

Type
Optional
Yes

No parameters are passed

onLoad

Called when loadScript succeeds.

Type
Optional
Yes

The parameters are passed in by the external data source

timeout

Time to allow for the request in seconds

Type
Optional
Yes
useCache

Allow a cached response

Type
Default
false
Optional
Yes

Returns

Description

This can be used cross domain, but should only be used with trusted sources as any javascript included in the script will be executed.

Example

glow.net.loadScript("http://www.server.com/json/tvshows.php?jsoncallback={callback}", {
  onLoad: function(data) {
    alert("Data loaded");
  }
});
post

Makes an HTTP POST request to a given url

Synopsis

glow.net.post(url, data, opts);

Parameters

url
Type

Url to make the request to. This can be a relative path. You cannot make requests for files on other domains, to do that you must put your data in a javascript file and use glow.net.loadScript to fetch it.

data
Type
|

Data to post, either as a JSON-style object or a urlEncoded string

opts
Type

Same options as glow.net.get

Returns

glow.net.Request | glow.net.Response

A response object for non-defered sync requests, otherwise a request object is returned

Example

glow.net.post("myFile.html", {key:"value", otherkey:["value1", "value2"]}, {
  onLoad: function(response) {
    alert("Got file:\n\n" + response.text());
  },
  onError: function(response) {
    alert("Error getting file: " + response.statusText());
  }
});
put

Makes an HTTP PUT request to a given url

Synopsis

glow.net.put(url, data, opts);

Parameters

url
Type

Url to make the request to. This can be a relative path. You cannot make requests for files on other domains, to do that you must put your data in a javascript file and use glow.net.loadScript to fetch it.

data
Type
|

Data to put, either as a JSON-style object or a urlEncoded string

opts
Type

Same options as glow.net.get

Returns

glow.net.Request | glow.net.Response

A response object for non-defered sync requests, otherwise a request object is returned

Example

glow.net.put("myFile.html", {key:"value", otherkey:["value1", "value2"]}, {
  onLoad: function(response) {
    alert("Got file:\n\n" + response.text());
  },
  onError: function(response) {
    alert("Error getting file: " + response.statusText());
  }
});
send

Makes a custom HTTP request to a given url

Synopsis

glow.net.send(method, url, data, opts);

Parameters

method
Type

The HTTP method to use for the request. Methods are case sensitive in some browsers.

url
Type

Url to make the request to. This can be a relative path. You cannot make requests for files on other domains, to do that you must put your data in a javascript file and use glow.net.loadScript to fetch it.

data
Type
|
Optional
Yes

Data to post, either as a JSON-style object or a urlEncoded string

opts
Type

Same options as glow.net.get

Returns

glow.net.Request | glow.net.Response

A response object for non-defered sync requests, otherwise a request object is returned

Description

Not all HTTP verbs work cross-browser. Use get, post, put or del for 'safe' methods.

Example

glow.net.send('HEAD', 'myFile.html', null, {
  onLoad: function(response) {
    // ...
  }
});
xDomainGet

Makes a cross-domain GET request.

Synopsis

glow.net.xDomainGet(url, opts);

Parameters

url
Type

url to perform the request on The address that the GET request should be sent to.

opts
Type

Zero or more of the following as properties of an object:

blankUrl

url to load after main request

Type
Default
'/favicon1.ico'
Optional
Yes

the path of a blank URL on the same domain as the caller (default '/favicon1.ico')

onLoad

callback called when the request completes

Type
Optional
Yes

a callback that is called when the response to the post is recieved. The function is passed a single parameter containing the value of window.name set by the response to the post.

onTimeout

callback called when request times out

Type
Optional
Yes

a callback that is called when the requested url takes longer than the timeout to respond

timeout

request timeout

Type
Default
10
Optional
Yes

the request timeout in seconds (default 10 seconds)

Description

A form is constructed in a hidden iframe to make the request.

The URL that's requested should respond with a blank html page containing JavaScript that assigns the result data to window.name as a string, for example:

<script type="text/javascript"> window.name = '{ "success": true }'; </script>

xDomainPost

Makes a cross-domain POST request.

Synopsis

glow.net.xDomainPost(url, data, opts);

Parameters

url
Type

url to perform the request on the URL to post the data to.

data
Type

the data to post. This should be keys with String values (or values that will be converted to strings) or Array values where more than one value should be sent for a single key.

opts
Type

Zero or more of the following as properties of an object:

blankUrl

url to load after main request

Type
Default
'/favicon1.ico'
Optional
Yes

the path of a blank URL on the same domain as the caller (default '/favicon1.ico')

onLoad

callback called when the request completes

Type
Optional
Yes

a callback that is called when the response to the post is recieved. The function is passed a single parameter containing the value of window.name set by the response to the post.

onTimeout

callback called when request times out

Type
Optional
Yes

a callback that is called when the requested url takes longer than the timeout to respond

timeout

request timeout

Type
Default
10
Optional
Yes

the request timeout in seconds (default 10 seconds)

Description

A form is constructed in a hidden iframe to make the request.

The URL that's requested should respond with a blank html page containing JavaScript that assigns the result data to window.name as a string, for example:

<script type="text/javascript"> window.name = '{ "success": true }'; </script>

Classes

Request

Returned by post, get async requests and loadScript

Response

Provided in callbacks to glow.net.post and glow.net.get

Documentation generated by 2.1.0 on Thu Jul 07 2011 12:47:29 GMT+0100 (BST)

³ÉÈË¿ìÊÖ iD

³ÉÈË¿ìÊÖ navigation

³ÉÈË¿ìÊÖ Â© 2014 The ³ÉÈË¿ìÊÖ is not responsible for the content of external sites. Read more.

This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.