ScriptSrcIO Page

ScriptSrcIO test page: How To | Simple and Polling Tests | JSONP And JSON Callback Tests | DSR ID/Multipart Tests

Prevent Cache Force Single Request Add Content Parameters

## Simple and Polling (checkString) Tests

- Simple: Test no checkString and no timeout. So basically does nothing except add the script src element.
- Polling: Test loading (Should say first task is take out trash)
- Polling: Test bad loading (timeout)
- Polling: Test checkString with no timeout (bad checkString, so it will never finish polling, but no messages).

JSONP and JSON Callback Tests

Use "callback" as JSON callback parameter instead of "jsonp"
URL:
Query Params (should be proper name=urlEncodedValue&name=urlEncodedValue... syntax):
(Should print out "animalType is mammal")
(May see error message since it is a bogus URL)

DSR ID/Multipart Tests

URL:
Constant Params:
Query Params (should be proper name=urlEncodedValue&name=urlEncodedValue... syntax):
(May see error message since it is a bogus URL)

How to Use ScriptSrcIO/ScriptSrcTransport

ScriptSrcIO (which provides ScriptSrcTransport) allows for four basic types of requests:

- Simple
- Polling
- JSONP and JSON Callbacks
- DSR/Multipart

Each type uses <script src="url"></script> to accomplish the request. To use ScriptSrcIO, use the following require statements:

- dojo.require("dojo.io.*");
- dojo.require("dojo.io.ScriptSrcIO");

and use the normal dojo.io.bind() method. To force a ScriptSrcTransport request, use transport: "ScriptSrcTransport" in the keyword arguments to dojo.io.bind(). ScriptSrcTransport also implements the transport.canHandle() method, but since the requirements for ScriptSrcTransport are a subset of XMLHTTPTransport, and XMLHTTPTransport will be registered as a transport before ScriptSrcTransport (ScriptSrcTransport depends on BrowserIO.js, which will register XMLHTTPTransport), it is unlikely that ScriptSrcTransport's canHandle() will be called. So, the explicit transport argument is suggested.

Here is a list of bind() keyword arguments that are supported for all types of requests. The four types of transport requests are:

Simple
Simply adds a script element with a src. Does not do any polling and does not expect a callback. Also does not support any timeouts. Example:

    dojo.io.bind({
    	url: "http://the.script.url/goes/here",
    	transport: "ScriptSrcTransport"
    });

Polling
Adds a script element with a src. It will poll to see if a typeof expression does not equal undefined. When the typeof check succeeds, a load callback is called. Timeout and error callbacks are supported with this type of request. Example:

    dojo.io.bind({
    	url: "http://the.script.url/goes/here",
    	transport: "ScriptSrcTransport",
    	checkString: "foo", //This means (typeof(foo) != undefined) indicates that the script loaded.
    	load: function(type, data, event, kwArgs) { /* type will be "load", data and event null, , and kwArgs are the keyword arguments used in the dojo.io.bind call. */ },
    	error: function(type, data, event, kwArgs) { /* type will be "error", data and event will have the error, , and kwArgs are the keyword arguments used in the dojo.io.bind call. */ },
    	timeout: function() { /* Called if there is a timeout */},
    	timeoutSeconds: 10 //The number of seconds to wait until firing timeout callback in case of timeout.
    });

JSONP and JSON Callbacks
Adds a script element with a src. This sort of usage allows using services that use the JSONP convention to specify the callback that the server will use. Specify the name of the JSONP callback parameter using jsonParamName. Yahoo! Web Services use a jsonParamName of "callback". Some other services use jsonParamName of "jsonp". Timeouts are supported with this type of request. Example for a data service that uses "callback" as the URL parameter:

    dojo.io.bind({
    	url: "http://the.script.url/goes/here",
    	transport: "ScriptSrcTransport",
    	jsonParamName: "callback",
    	load: function(type, data, event, kwArgs) { /* type will be "load", data will be response data,  event will null, and kwArgs are the keyword arguments used in the dojo.io.bind call. */ },
    	error: function(type, data, event, kwArgs) { /* type will be "error", data will be response data,  event will null, and kwArgs are the keyword arguments used in the dojo.io.bind call. */ },
    	timeout: function() { /* Called if there is a timeout */},
    	timeoutSeconds: 10 //The number of seconds to wait until firing timeout callback in case of timeout.
    });

DSR/Multipart
Adds a script element with a src. Uses the Dynamic Script Request convention to specify the callback that the server will use. Multipart requests (splitting a long request across multiple GET requests) is supported. Timeout and error callbacks are supported with this type of request. Example:

    dojo.io.bind({
    	url: "http://the.script.url/goes/here",
    	transport: "ScriptSrcTransport",
    	useRequestId: true, //adds the _dsrId to request with a generated ID. If a specific request ID is wanted, use apiId: "myId" instead
    	//optional: forceSingleRequest: true, //Will not segment the request to multipart requests even if it is a long URL.
    	constantParams: "name1=value1&name2=value2" //params to be sent with each request that is part of a multipart request. See spec.
    	load: function(type, data, event, kwArgs) { /* type will be "load", data will be response data, event will be onscriptload event, and kwArgs are the keyword arguments used in the dojo.io.bind call. */ },
    	error: function(type, data, event, kwArgs) { /* type will be "error", data will be response data, event will be onscriptload event, and kwArgs are the keyword arguments used in the dojo.io.bind call. */ },
    	timeout: function() { /* Called if there is a timeout */},
    	timeoutSeconds: 10 //The number of seconds to wait until firing timeout callback in case of timeout.
    });

Common bind() arguments
ScriptSrcTransport supports the following arguments across all types of requests. In general, all of these arguments have the same meaning and use in XMLHTTPTransport.

- formNode: Uses a form to generate query parameters.
- backButton, back, forward, forwardButton, changeUrl: used to register a back/forward handler. See dojo.undo.browser for more info.
- content: a JS object that gets turned into query parameters.
- postContent: Adds raw name=value parameters to query parameters.
- sendTransport: Adds dojo.transport=scriptsrc to query parameters.
- preventCache: Adds dojo.preventCache=[unique ID] to bypass browser cache and force a fresh GET.
- handle: A function that accepts the following arguments: function(type, data, event) {}. This can be used instead of specifying a separate load, error and timeout handler. The type parameter will be a string that specifies the callback type ("load", "error", "timeout").