With Xajax do a no refresh PHP two-level linkage

Source: Internet
Author: User
Tags connect require

There are two tables in the database: Large classification Bigtype table and small classification Smalltype table.

Bigtype in the table: Id,bigname;

Smalltype in the table: Smallid,bigid,smallname;

Train of thought: (mainly according to gourd, according to the official example of the whole) first read a large classification table, to achieve large classification, when the large classification of each selection, the selected large classification ID submitted to the server side, through the ID of the corresponding small classification value, the query value returned, insert the appropriate position (note: Because of the Xajax to the client page inserted JavaScript part is not skilled, here I directly to the small classification of the value of the server in order to output the select list menu, so feel a little strange, not very pure feeling ^_^, but has met my needs, did not continue to tune, If there is an opportunity to be improved in the future)

Contains three file structures:

xajaxserver.php

xajaxcommon.php

chose.php

Code references are as follows:

Code for xajaxcommon.php pages

View Plaincopy to Clipboardprint?

function library file containing Xajax
Require_once ("./xajax/xajax_core/xajax.inc.php");

Create a Xajax Object
$xajax = new Xajax ("xajaxserver.php");

Register a function that you want to call via Xajax, which obtains a small classification by a large category ID.
$xajax->registerfunction ("Getsmalltype");
function library file containing Xajax
Require_once ("./xajax/xajax_core/xajax.inc.php");

Create a Xajax Object
$xajax = new Xajax ("xajaxserver.php");

Register a function that you want to call via Xajax, which obtains a small classification by a large category ID.
$xajax->registerfunction ("Getsmalltype");

Code for xajaxserver.php pages
View Plaincopy to Clipboardprint?
Output Chinese, set GB2312
Define (' xajax_default_char_encoding ', ' GB2312 ');

Include Common Files
Require ("xajaxcommon.php");

A function that queries a small taxonomy by Bigid and returns an XML command through the Xajaxresponse object:
function Getsmalltype ($BigID)
{
$objResponse = new Xajaxresponse ();
/*
* Connect to your database and query for the value of the small category by $bigid, the part of the code skipped
* The result of the small classification is stored in the two-dimensional array $smalltyperesult
*/

Start constructing the Select list menu
$j = 0;
while (!emptyempty ($SmallTypeResult [$j]))
{
$Temp. = "<option value= '". $SmallTypeResult [$j][id]. "' > ".
$SmallTypeResult [$j][smallname]. " </option> ";
$j + +;
}
$str = "<select name= ' smalltype ' id= ' Smalltype ' >
<option value= ' 0 ' >[Select Small classification]</option> ";
$str. = $Temp;
$str. = "</select>";

Display the list menu in a layer with the ID of the request page Mdjingdiv
$objResponse->assign ("Mdjingdiv", "InnerHTML", $str);
return $objResponse;
;
}

The request is processed by Xajax before the program outputs
$xajax->processrequest ();
Output Chinese, set GB2312
Define (' xajax_default_char_encoding ', ' GB2312 ');

Include Common Files
Require ("xajaxcommon.php");

A function that queries a small taxonomy by Bigid and returns an XML command through the Xajaxresponse object:
function Getsmalltype ($BigID)
{
$objResponse = new Xajaxresponse ();
/*
* Connect to your database and query for the value of the small category by $bigid, the part of the code skipped
* The result of the small classification is stored in the two-dimensional array $smalltyperesult
*/

Start constructing the Select list menu
$j = 0;
while (!empty ($SmallTypeResult [$j]))
{
$Temp. = "<option value= '". $SmallTypeResult [$j][id]. "' > ".
$SmallTypeResult [$j][smallname]. " </option> ";
$j + +;
}
$str = "<select name= ' smalltype ' id= ' Smalltype ' >
<option value= ' 0 ' >[Select Small classification]</option> ";
$str. = $Temp;
$str. = "</select>";

Display the list menu in a layer with the ID of the request page Mdjingdiv
$objResponse->assign ("Mdjingdiv", "InnerHTML", $str);
return $objResponse;
;
}

The request is processed by Xajax before the program outputs
$xajax->processrequest ();

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.