Login Register

IFrame I/O

The IFrame I/O transport is useful because it can upload files to the server. Example usage:

<script type="text/javascript">

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

dojo.require("dojo.io.IframeIO");



function mySubmit() {

dojo.io.bind ({

url: 'server.cfm',

handler: callBack,

mimetype: "text/plain",

formNode: dojo.byId('myForm')

});

}
   function callBack(type, data, evt) {

//The data object will be different

//depending on the mimetype used in the dojo.io.bind()

//call. See below for more info.

dojo.byId('result').innerHTML = data;

}

</script>


The response type from the above URL can be text, html, or JS/JSON.

IframeIO responses need to be a little different from the ones that are sent back from XMLHttpRequest responses. Because an iframe is used, the only reliable, cross-browser way of knowing when the response is loaded is to use an HTML document as the return type.

If the return type (specified by the mimetype) is text/plain, text/javascript or text/json, then the server response should be an HTML page that has a <textarea> element. The data that you want returned to the dojo.io.bind() load callback should be the text inside the textarea element. For the text/javascript or text/json return types, the text inside the textarea element will be converted to JavaScript or JSON, repectively, and that will be the data sent to the load callback.

If the return type is text/html as the return type, then the data parameter will be the complete HTML document that is in the iframe.

For IframeIO, XML responses are not supported because we can't get a nice cross-browser solution. If you want text/html as the mimetype, what you get back is the document object for the document in the iframe.

See these tests for more info:

text/plain: http://archive.dojotoolkit.org/nightly/tests/io/test_IframeIO.text.html

text/html: http://archive.dojotoolkit.org/nightly/tests/io/test_IframeIO.html.html

text/javascript: http://archive.dojotoolkit.org/nightly/tests/io/test_IframeIO.html