3发送ajax post方式(3post01.html)
2025年8月24日小于 1 分钟
html示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3发送ajax post方式</title>
<style type="text/css">
#dvs{width:300px;height:300px;border:solid 1px blue;}
</style>
</head>
<body>
<button>post 请求方式</button>
<div id='dvs'></div>
<script type="text/javascript">
var buts=document.getElementsByTagName('button')[0];
var dvs= document.getElementById('dvs');
buts.onclick=function()
{
//1实例化
var x = new XMLHttpRequest;
//2触发事件
x.onreadystatechange=function()
{
//判断
if(x.readyState==4 && x.status==200)
{
//console.log(x.responseText);
dvs.innerHTML=x.responseText;
}
}
//初始化
x.open("POST","3post01.php",true);
x.setRequestHeader('content-type','application/x-www-form-urlencoded');
//发送
x.send('id=100&&name=www');
}
</script>
</body>
</html>
对应的3post01.php
<?php
//接收传值
//$post=$_POST;
var_dump($_POST);