標籤: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實現非同步