标签:提交 request open document ons href microsoft 快速 cti
php实现ajax请求的方法
Ajax页面:
第一,了解底层逻辑,正是平常的1个提交在无刷新的条件下发出请求后完成回应,之后去针对你需要
的条件来做动作。
<!DOCTYPE html>
<html>
<head>
<script>
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","send.php?name=sunzhiyan",true);
xmlhttp.send();
}
</script>
</head>
<body> <div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button> </body>
</html>
PHP页面:
在这里了需注意,如果是利用get方式 传输的一定要利用$_GET方式 才可以接收值,不然则$_POST
1 <?php 2 3 if($_GET[‘name‘] == sunzhiyan){ 4 5 echo ‘this is right‘; 6 7 }else{ 8 9 echo ‘this is error‘; 10 11 } 12 13 ?>
它是简单的1个Ajax的操作,可以完成Ajax的效验。
推荐阅读:怎么快速优化网站排名?
标签:提交 request open document ons href microsoft 快速 cti
原文地址:https://www.cnblogs.com/x1aoguaishou/p/13024053.html