Simple PHP + Ajax application

Source: Internet
Author: User

<Script language = 'javascript 'Type = 'text/JavaScript '>

Function initajax () // initialize the Ajax object
{
// Return "adfasd ";
VaR Ajax = false;
Try {
Ajax = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Ajax = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){
Ajax = false;
}
}
If (! Ajax & typeof XMLHttpRequest! = 'Undefined '){
Ajax = new XMLHttpRequest ();
}
Return Ajax;
}

</SCRIPT>

//////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////

<Select name = "typeid" id = "typeid" onchange = "getch1_type ();">
<Option value = "-1"> merchant type </option>
<? Foreach ($ type as $ v) {?>
<Option value = "<? = $ V [linkageid]?> "> <? = $ V ['name']?> </Option>
<? }?>
</SELECT> </span> <span id = "show"> </span>

//////////////////////////////////////// //////////////////////////////////////// ///////////////////////////////////////

<SCRIPT>
Function getchlidtype ()
{

// URL for Ajax
VaR pid = Document. getelementbyid ("typeid ");

VaR url = "http: // 192.168.0.102/youyuanhui_com/ajax/getoption. php? PID = "+ PID. value;

// Obtain the position of the news display Layer
VaR show = Document. getelementbyid ("show ");

// Instantiate an Ajax object
VaR Ajax = initajax ();

// GET requests
Ajax. Open ("get", URL, true );

// Obtain the execution status
Ajax. onreadystatechange = function (){
// If the execution is normal, the returned content is assigned to the layer specified above.
If (Ajax. readystate = 4 & Ajax. Status = 200 ){

Show. innerhtml = Ajax. responsetext;
}
}
// Sending Blank
Ajax. Send (null );
}
</SCRIPT>

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////////

Getoption. php

<? PHP
Require '../include/common. Inc. php ';
Require '../include/system_info.php ';
Global $ dB;
If ($ pid = $ _ Get ["PID"])
{
$ Options = $ db-> select ("select * From yyh_linkage where parentid =". $ PID );
Echo "<select name = 'typeid2' id = 'typeid2'> ";
Echo "<option value = '-1'>-select subclass </option> ";
Foreach ($ options as $ OPT)
{
Echo "<option value =". $ OPT ['linkageid']. ">". $ OPT ['name']. "</option> ";
}
Echo "</SELECT> ";
}
?>

Principle: assume A and B have two pages.

Page A is an Ajax request. To display data information on page A, page a requests page B through Ajax, and page B displays the corresponding data on page B after obtaining the data, the content of page B is returned to page.

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: info-contact@alibabacloud.com 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.