multipart = true;
xhr.open("GET", url, true);
xhr.onload = handleLoad;
xhr.send(null);
}
When the data is received, just look at it as a normal XHR, though given the format, you
will likely be only using responseText.
function handleLoad(event)
{
document.getElementById("responseOutput").style.display = "";
document.getElementById("responseOutput").innerHTML +=
"
xhr.responseText
" + event.target.responseText;
}
To see this example working under supporting browsers, visit http://ajaxref.com/ch3/
multipart.html.
onProgress and Partial Responses
Firefox already implements a few useful event handlers for the XMLHttpRequest object. The
most interesting is the onprogress handler, which is similar to readyState with a value of
3 but is different in that it is called every so often and provides useful information on the
progress of any transmission. This can be consulted to not only look at the responseText as
it is received, but also to get a sense of the current amount of content downloaded versus the
total size. The following code snippet sets up an XHR to make a call to get a large file and
associates a callback for the onprogress handler:
var url = "http://ajaxref.com/ch3/largefile.php";
var xhr = createXHR();
if (xhr)
{
xhr.onprogress = handleProgress;
xhr.open("GET", url, true);
xhr.
Pages:
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173