<!DOCTYPE html>

<html>

<head lang="en">

<meta charset="UTF-8">

<title></title>

</head>

<body>

{{ time }}

<input type="button" value="XMLHttpRequest按钮;" οnclick="XHRAjax();"><br>

<input type="button" value="XMLHttpRequestForm按钮;" οnclick="XHRAjaxForm();">





<br>

<a οnclick="UploadFile();" value="按钮1" style="color: red">XMLHttpRequests上传</a>



</body>

<script>

function XHRAjax(){

var xhr=new XMLHttpRequest();

xhr.onreadystatechange=function()

{

if(xhr.readyState==4)

{

//服务器端响应的内容已经接收完毕

console.log(xhr.responseText);

}



};

{# xhr.open("GET","/xhr_ajax/?p=123");#}



{# xhr.send();#}

xhr.open("POST","/xhr_ajax/");

xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset-UTF-8");

xhr.send("k1=v1;k2=v2");



}



function XHRAjaxForm(){

var xhr=new XMLHttpRequest();

xhr.onreadystatechange=function()

{

if(xhr.readyState==4)

{

console.log("OK");

}



};

xhr.open("POST","/xhr_ajax/");

{# xhr_ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset-UTF-8");#}

var form=new FormData();

form.append("user","alex");

form.append("pwd","123");

xhr.send(form);





}





</script>

</html>