Encapsulation of JavaScript XHR objects (cross-browser)

Source: Internet
Author: User

  • Loading documents:
    /*@desc 加载XHR文件@author lee [<[email protected]>]@param file 文件路径@param async 同步或异步 true 异步 flase 同步@return xmlDoc 加载后的内容*/function loadDoc(file,async=true){if(window.XMLHttpRequest){  // code for IE7+, Firefox, Chrome, Opera, Safari    xmlhttp=new XMLHttpRequest();}else{  // code for IE6, IE5    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.open("GET",file,async);xmlhttp.send();xmlDoc=xmlhttp.responseXML;return xmlDoc}
  • Load string:
    /*@desc 加载XML文档@author lee [<[email protected]>]@param txt 字符串@param async 同步或异步 true 同步 flase 异步@return xmlDoc 加载后的DOM对象*/function loadStr(txt,async=true){if(window.DOMParser){    parser=new DOMParser();    xmlDoc=parser.parseFromString(txt,"text/xml");}else{  // Internet Explorer    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");    xmlDoc.async=async;    xmlDoc.loadXML(txt);}return xmlDoc}
  • Encapsulation of JavaScript XHR objects (cross-browser)

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.