XMLHTTPrequest2
object is used by the Chrome, Firefox, Opera, Safari and the XDomainRequest
object is used by the Internet Explorer.
[c]function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
}
else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
}
else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
}
return xhr;
}
var xhr = createCORSRequest('GET', url);
if (!xhr) {
throw new Error('CORS not supported');
}
[/c]
Event Handler | Description |
---|---|
bad_alloc | Occurs when failure in memory allocation |
onloadstart | Used to start the request |
bad_typeid | Exception thrwon by typeid function |
bad_function_call | Exception thrwon when an empty function is called |
onprogress | Used to loads the data and send the data |
onabort | Used to abort the request |
onerror | used to action request has failed |
onload | Used to load successfully |
ontimeout | Request should complete before the timeout |