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 = "
| School Number |
Name |
Address |
Class |
"; foreach ($info as $v) {$result. ="
| {$v [' Sid ']} |
{$v [' name ']} |
{$v [' address ']} |
{$v [' CID ']} |
";} $result. = "
";
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.