Ö÷²¥´óÐã

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

Sending data to & from the server

Further Info & Examples

Methods

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()

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.Response

An integer identifying the async request, or the response object for sync requests

Example

var postRef = 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());
    }
  }
);

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 Mon Jul 20 2009 14:55:30 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.