我有一个结果页面,显示调查答案的图表。这些图表是通过执行 SQL 的 PHP 文件生成的。结果页面需要包含一些过滤,因此我尝试使用 AJAX 更新 SQL 以显示而不重新加载所述结果页面。
通过表格选择过滤器的类型;
<form name="sqlselector" action= "javascript" onsubmit"ajaxFunction('barscompleteCCC.php? course=' + document.getElementById('course').value);">
<select name="course">
<option value="All">All</option>
<?php $result= mysql_query('SELECT * FROM tCourse'); ?>
<?php while($row= mysql_fetch_assoc($result))
{ ?>
<option value="<?php echo htmlspecialchars($row['CourseID']);?>">
<?php echo htmlspecialchars($row['CourseName']); ?>
</option>
<?php
}
?>
</select>
<input type="submit" value="Build">
</form>
阿贾克斯是:
ajaxConnection.onreadystatechange = ajaxReply; // whenever the ready state is changed
ajaxConnection.open('GET', url, true); // opens a request to server
ajaxConnection.send(null); // closes the request
// Now, the code waits unless the ready state changes.
// After every change ajaxReply() is executed
return true;
} // end function ajaxFunction
function ajaxReply() { // your code's logic goes here
if (ajaxConnection.readyState == 4)
{ // 4 mean page loaded successfully
if (ajaxConnection.status == 200)
{ // 200 mean all is OK
document.getElementById('course').innerHTML = ajaxConnection.responseText;
} // end if
else
{ // if the status code is anything else (a rare case though)
alert('Something weird occurred. HTTP error code ' + ajaxConnection.status.toString() + 'yoko.');
return; // exit
}
} // end if
我想动态更改的变量位于 PHP 文件中:
session_start();
$course = $_GET['course'];
请,任何帮助将不胜感激。:-)