筆記--js實現非同步

來源:互聯網
上載者:User

標籤:turn   log   class   blog   null   通訊   清除   type   state   

<script type="text/javascript">var xhr=false;function createXhr() {var xhobj = false;try {xhobj = new ActiveXObject("Msxml2.XMLHTTP"); // ie msxml3.0+} catch (e) {try {xhobj = new ActiveXObject("Microsoft.XMLHTTP"); //ie msxml2.6} catch (e2) {xhobj = false;}}if (!xhobj && typeof XMLHttpRequest != ‘undefined‘) {// Firefox, Opera 8.0+, Safarixhobj = new XMLHttpRequest();}return xhobj;}

 


function doDel(du,ot,id){//當執行刪除時候建立非同步對象xhr=createXhr();if(confirm("您確定要刪除此地址嗎?")){//設定非同步請求的參數(傳值方式類型,du--default是否預設&ot--ordertype賬戶類型&aid地址編號,是否執行非同步)xhr.open(‘get‘,‘DoDelAdd.ashx?Du=‘+du+‘&Ot=‘+ot+‘&aid=‘+id,true);//清除緩衝(設定get請求不用緩衝)xhr.setRequestHeader("If-Modified-Since","0");//設定回呼函數xhr.onreadystatechange=function(){//檢查準備狀態 0--未初始化,1--載入,2--載入完成,3-正在互動,4--完成互動if(xhr.readyState==4){//通訊成功if(xhr.status==200){//獲得傳回值var res=xhr.responseText;//判斷if(res=="OK"){//擷取要刪除行的idvar nowtr=document.getElementById("mrdz1"+id);nowtr.parentNode.removeChild(nowtr);}}}}xhr.send(null);}}</script>

 

筆記--js實現非同步

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.