亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于Ajax寫的順序的好壞

關于Ajax寫的順序的好壞

函數式編程 2019-03-01 18:22:37
window.onload = function() {var oBtn = document.getElementById('btn');oBtn.onclick = function() {        var xhr = new XMLHttpRequest();        xhr.onreadystatechange = function() {        if (xhr.readyState == 4) {            if ( xhr.status == 200 ) {                alert( xhr.responseText );            }        }    }//教程中說把監聽的事件函數寫在xhr.open('get', '1.txt', true);xhr.send();前面比較好,為什么呢?        xhr.open('get', '1.txt', true);    xhr.send();        }}下面這么寫也沒處問題額?window.onload = function() {var oBtn = document.getElementById('btn');oBtn.onclick = function() {        //打開瀏覽器    var xhr = new XMLHttpRequest();    //在地址欄輸入地址    xhr.open('get','1.txt',true);    //提交    xhr.send();        //等待服務器返回內容    xhr.onreadystatechange = function() {                if ( xhr.readyState == 4 ) {            alert( xhr.responseText );        }            }    }}
查看完整描述

2 回答

?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

ajax執行他執行某個方法之后 尋找對應的下一個方法 和書寫順序沒關系

但是建議按順序寫 遵循JS書寫規律和執行規律


查看完整回答
反對 回復 2019-03-03
  • 2 回答
  • 0 關注
  • 444 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號