Php development-AJAX 1
AJAX was just introduced two days ago. It is very useful to hear from others. I think it is necessary to learn it.
The following is an example of passing parameters to the php page through the get method:
Test.html
<Script type = text/javascript src = test. js> </script>
Test. js
Var xmlHttp; function GetXmlHttpObject () {if (window. XMLHttpRequest) {// code for IE7 +, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest ();} else {// code for IE6, IE5 xmlhttp = new ActiveXObject (Microsoft. XMLHTTP);} return xmlhttp;} // ----------- ajax method ----------- // function testcheck () {xmlHttp = GetXmlHttpObject (); if (xmlHttp = null) {alert ('your browser does not support AJAX! '); Return;} var url = http: // localhost/PHPTEST/index. php? Isbn = 110120; // be sure to pay attention to this part. At the beginning, I added a space in front of '='. As a result, the php page could not obtain the parameter, everyone must pay attention to xmlHttp. open (GET, url, true); xmlHttp. onreadystatechange = getOkGet; // after the event is sent, the message is received and the xmlHttp function is called. send ();} function getOkGet () {if (xmlHttp. readyState = 1 | xmlHttp. readyState = 2 | xmlHttp. readyState = 3) {// local prompt: loading} if (xmlHttp. readyState = 4 & xmlHttp. status = 200) {alert (xmlHttp. responseText); alert ('20140901'); // process returned results }}
Index. php
In addition, the url of test. js should be the path of your file.
Let's take a look at the running effect.