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

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
String

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
Object

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
String

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
Object

Options Object of options.

async

Should the request be performed asynchronously?

Type
Boolean
Default
true
Optional
Yes
defer

Do not send the request straight away

Type
Boolean
Default
false
Optional
Yes

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

forceXml

Treat the response as XML.

Type
Boolean
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
Object
Optional
Yes

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

onAbort

Callback to execute if the request is aborted

Type
Function
Optional
Yes
onError

Callback to execute if the request was unsucessful

Type
Function
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
Function
Optional
Yes

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

timeout

Time to allow for the request in seconds

Type
Number
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
Boolean
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
String

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
Object
Optional
Yes

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

charset

Charset attribute value for the script

Type
String
Optional
Yes
onAbort

Called if the request is aborted

Type
Function
Optional
Yes
onError

Called on timeout

Type
Function
Optional
Yes

No parameters are passed

onLoad

Called when loadScript succeeds.

Type
Function
Optional
Yes

The parameters are passed in by the external data source

timeout

Time to allow for the request in seconds

Type
Number
Optional
Yes
useCache

Allow a cached response

Type
Boolean
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
String

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
Object | String

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

opts
Type
Object

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
String

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
Object | String

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

opts
Type
Object

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
String

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

url
Type
String

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
Object | String
Optional
Yes

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

opts
Type
Object

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
String

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

opts
Type
Object

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

blankUrl

url to load after main request

Type
String
Default
'/favicon.ico'
Optional
Yes

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

onLoad

callback called when the request completes

Type
Function
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
Function
Optional
Yes

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

timeout

request timeout

Type
Number
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
String

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

data
Type
Object

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
Object

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

blankUrl

url to load after main request

Type
String
Default
'/favicon.ico'
Optional
Yes

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

onLoad

callback called when the request completes

Type
Function
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
Function
Optional
Yes

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

timeout

request timeout

Type
Number
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 JsDoc Toolkit 2.1.0 on Thu Jul 07 2011 12:47:29 GMT+0100 (BST)

BBC navigation

BBC © 2014 The BBC 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.