php中使用Ajax

来源:互联网 发布:歼-20知乎 编辑:程序博客网 时间:2024/06/06 14:14

要每次请求都要使用一个新的XMLHttpRequest


 如果使用GET将数据传给服务器,则服务器就使用$_GET 就直接通过Url将数据传给服务器(server.php?var1=value1&var2=value2)

IE可能存在缓存问题,可以再url中加入一个一直改变的参数,如:time=new Date()

xmlhttp.open("GET","server.php?var1=value1&var2=value2",true);

xmlhttp.send(null);

 

 

 使用POST时一定要使用 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xmlhttp.open("POST","server.php",true);

xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xmlhttp.send("var1=value1&var2=value2");

 

原创粉丝点击