Ajax让地址传值变成POST的形式

<?php
//reg_new.php
if($_POST){
echo $_POST['text'];
}else{
echo $_REQUEST['text'];
}
?>
<input type="text" id="text" value="我是中国人">
<input type="button" name="button" value="myAjax" onclick="post_test()">

<script language="javascript" type="text/javascript">
var request;
function createxmlHttpRequest(){//判断浏览器类型,创建xmlHttpRequest对象
if(!request){
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
}else{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
}
}
function post_test(){//post发送模式
createxmlHttpRequest();
var url = "reg_new.php";
var send = "regbase=123";
request.open("post", url);
request.onreadystatechange = callback;
request.setRequestHeader("content-type", "application/x-www-form-urlencoded");
request.send(send);
}
function callback(){//回调函数
if (request.readyState == 4){
if (request.status == 200){
alert(request.responseText);
}else if(request.status == 404){
alert("该路径未找到");
}else if(request.status == 403){
alert("禁止访问");
}else{
alert("status is " + request.status);
}
}
}
</script>

评论列表

此文章还没有评论。