Pass the value via Ajax post, but return to empty to solve the idea

Source: Internet
Author: User
Pass the value via Ajax post, but return to null
First contact with Ajax, want to use a simple example to practice
There is a drop-down list in index.php that selects different classes to return different student information
The code is as follows:

 
  Take the class name out of the database and put it in the drop-down list
mysql_connect ("localhost", "root", "root") or Die ("database connection failed");
mysql_select_db ("Studentmanage") or Die ("database does not exist");

$sql = "SELECT * from class";
$rs =mysql_query ($sql);
$info =array ();
while ($row =mysql_fetch_assoc ($rs)) {
$info []= $row;
}

?>



Query Student Information







Please select a class:
Choose Class







Query the database through result.php and return the student information, the code is as follows:
 
  Header ("Content-type:text/html;charset=utf-8");
Header ("Content-type:text/xml;charset=utf-8");
Header ("Cache-control:no-cache");
$class =$_post[' class '];

mysql_connect ("localhost", "root", "root") or Die ("database connection failed");
mysql_select_db ("Studentmanage");
mysql_query ("Set names Utf-8");
$sql = "SELECT * from student where cid= ' $class '";
$sql = "SELECT * FROM student where cid=3";
$rs =mysql_query ($sql);
$info =array ();
while ($row =mysql_fetch_assoc ($rs)) {
$info []= $row;
}

$result = "



"; foreach ($info as $v) {$result. =" ";} $result. = "
School Number Name Address Class
{$v [' Sid ']} {$v [' name ']} {$v [' address ']} {$v [' CID ']}
";
echo $result;
?>


I tested the next result.php alone, I'm sure there's no problem, I can get the corresponding information from the database, but I can't get the information back to index.php.
Ask for help, find out where the problem is
------Solution--------------------
Set value for div? Even if your query is normal, you won't see the effect because the div's value is not displayed directly in the view.
What you need is innerhtml.
  • 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.