您好,登錄后才能下訂單哦!
Ajax界面:
首先,理解本質,就是普通的一個提交在無刷新的情況下發(fā)出請求后得到響應,然后去針對你需要
的情況來做行為。
<!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"><h3>Let AJAX change this text</h3></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如何實現ajax請求的詳細內容,更多請關注億速云其它相關文章!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。