原生Get请求和Post请求

get()请求

function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}

xmlhttp.open("get","url",true);
xmlhttp.send();

}

post()请求

function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","/ajax/demo_post2.asp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Bill&lname=Gates");
}

两者之间的区别     

get()

1.存放位置:请求放入请求行中   url后

2.长度限制:2Kb

3.效率:相对高

4.只应用于取回数据

post()

 

1.存放位置:请求放入请求体中

 

2.长度限制:理论上没有长度限制

 

3.效率:相对低

 

4.安全性:相对于get()高一些  但两者都没有绝对的安全

 

 

posted @ 2017-09-11 13:27  小lv豆  阅读(186)  评论(0编辑  收藏  举报