php如何实现ajax请求-PHP问题

资源魔 22 0

php完成ajax的接纳

Ajax界面:

起首,了解实质,就是一般的一个提交正在无刷新的状况下收回申请后失去呼应,而后去针对你需求

的状况来做行为。

<!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

<?php
if($_GET['name'] == sunzhiyan){
 echo 'this is right';
}else{
 echo 'this is error';
} 
?>

这是简略的一个Ajax的运用,可以完成Ajax的验证。

保举教程:《PHP教程》

以上就是php若何完成ajax申请的具体内容,更多请存眷资源魔其它相干文章!

标签: ajax php教程 php故障解决 php使用问题

抱歉,评论功能暂时关闭!