(Step five) using the native ajax

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

step: 

1) Creating an Ajax engine object XMLHttpRequest

 var xhr = new XMLHttpRequest();//创建对象


2) binding to listen to Ajax engine objects (server has to listen to the response data engine)

            //绑定监听对象
            xhr.onreadystatechange = function () {
                //监听readyState和status
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var value = xhr.responseText;//获取数据
                    alert(value);
                }
            }


3) submit binding address


//调用open发方法,
//指定请求的路径,
//是否是异步,true:异步
xhr.open("get", "/项目名/Servlet文件名?username=" + document.getElementById("username"), true);


4) sending a request

  //发送请求
   xhr.send();


5) receiving the response data

(Here after supplement)

Guess you like

Origin blog.csdn.net/longyanchen/article/details/93380775