Php development-AJAX 1: php development-AJAX

Source: Internet
Author: User

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:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.