Php development-AJAX 1: php development-AJAX
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
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 "; // You must note this. At the beginning, I added a space before '='. As a result, the php page cannot 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
<?php header('Content-type:text/html');if(isset($_GET['isbn'])){ $isbn =$_GET['isbn']; if(!$isbn){ echo("abc"); // print "That request was not understood"; }else if ($isbn =="110120") { echo($isbn); // print "JavaScript step by step"; }}else{ echo("aaa");}?>
In addition, the url of test. js should be the path of your file.
Let's take a look at the running effect.
The demo address is as follows: demo
I am eager to receive guidance from a Daniel !!!