Friday, September 20, 2013

xmlhttprequest

Date:20130921


if (typeof XMLHttpRequest === "undefined") {
  XMLHttpRequest = function () {
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
    catch (e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
    catch (e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) {}
    throw new Error("This browser does not support XMLHttpRequest.");
  };
}

xhr=new XMLHttpRequest();
//xhr.open('GET', 'somepage.xml', true); 
xhr.open('POST', 'somewhere', true);
//xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
    // do something to response
    console.log(this.responseText);
};  
//xhr.send(null); 
xhr.send('user=person&pwd=password&organization=place&requiredkey=key');

Reference:
http://en.wikipedia.org/wiki/XMLHttpRequest
http://www.w3schools.com/xml/xml_http.asp

No comments: