jQuey_Ajax的使用

來源:互聯網
上載者:User

標籤:通訊   ready   9.png   txt   script   發送   ges   innerhtml   非同步請求   

非同步呼叫,局部重新整理


Ajax工作流程

    XMLHttpRequest對象直接與伺服器通訊,非同步傳輸資料


Ajax實現步驟

    1.建立XMLHttprequest對象,作用:非同步請求,資料的傳送

    2.設定回呼函數:

        當伺服器做出正確響應返回後,需要對返回的資料進行處理,處理的代碼寫在回呼函數中

        回呼函數最後才調用

    3.初始化HttpRequest組件

    4.發送請求


Ajax原理

原生Ajax:

script>//1.擷取XMLHttpRequest對象的函數fuction getXMLHttpRequest(){if(window.XMLHttpRequest){return new XMLHttpRequest();}}var xht;//文字框失去焦點觸發的函數function inputLogin(txt){xhr = getXMLHttpRequest();//調用方法建立XMLHttpRequest對象//初始化XMLHttpRequest對象xhr.open("GET","AdminServlet?loginId" + loginId,true);//XMLHttpRequest對象發送請求xhr.send(null);}//3.回呼函數function resultFunction(){var s = ducument.getElementById("s");if(xhr.readyState == 4) { //請求完成if(xhr.status ==200) {  //表示服務端正確返回資料var data = xhr.responseText;if(data == "yes"){s.style.color = "green";s.innerHTML = "使用者名稱可用";}else{s.style.color = "red";s.innerHTML = "使用者名稱不可用";}}}}</script>


Ajax實現登入使用者名稱驗證




引入的jar包


迴圈輸出json資料


jQuey_Ajax的使用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.