我正在尝试实施Ajax技术
但是我没有得到什么问题
请帮我找出问题,找出问题。
我认为问题出在此页面上。
<html>
<body>
<script language = "javascript" type = "text/javascript">
//Browser Support Code
function ajaxFunction() {
var ajaxRequest;
try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4) {
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// Now get the value from user and pass it to
// server script.
var age = document.getElementById('age').value;
var wpm = document.getElementById('wpm').value;
var sex = document.getElementById('sex').value;
var queryString = "&age = " + age ;
queryString += "&wpm = " + wpm + "&sex = " + sex;
ajaxRequest.open("GET", "http://localhost/ajax-example.php" +
queryString, true);
ajaxRequest.send();
}
</script>
<form name = 'myForm'>
Max Age: <input type = 'text' id = 'age' /> <br />
Max WPM: <input type = 'text' id = 'wpm' /> <br />
Sex:
<select id = 'sex'>
<option value = "m">m</option>
<option value = "f">f</option>
</select>
<input type = 'button' onclick = 'ajaxFunction()' value = 'Query
MySQL'/>
</form>
<div id = 'ajaxDiv'>Your result will display here</div>
</body>
</html>
这是完成数据库代码的php页面 数据库名称为ajaxtutorials,表名称为ajax_example
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "ajaxtutorials";
$conn= mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
mysqli_select_db($conn, $dbname) or die(mysqli_error($conn));
$age = $_GET['age'];
$sex = $_GET['sex'];
$wpm = $_GET['wpm'];
$age = mysqli_real_escape_string($conn, $age);
$sex = mysqli_real_escape_string($conn, $sex);
$wpm = mysqli_real_escape_string($conn, $wpm);
$query = "SELECT * FROM ajax_example WHERE sex like '$sex'";
if(is_numeric($age))
$query .= " AND age <= $age";
if(is_numeric($wpm))
$query .= " AND wpm <= $wpm";
$qry_result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Name</th>";
$display_string .= "<th>Age</th>";
$display_string .= "<th>Sex</th>";
$display_string .= "<th>WPM</th>";
$display_string .= "</tr>";
// Insert a new row in the table for each person returned
while($row = mysqli_fetch_array($qry_result)) {
$display_string .= "<tr>";
$display_string .= "<td>$row[name]</td>";
$display_string .= "<td>$row[age]</td>";
$display_string .= "<td>$row[sex]</td>";
$display_string .= "<td>$row[wpm]</td>";
$display_string .= "</tr>";
}
echo "Query: " . $query . "<br />";
$display_string .= "</table>";
echo $display_string;
?>
请帮助我识别问题,找出问题。
我认为问题出在此页面上。
单击按钮时出现错误
找不到对象 在此服务器上找不到请求的URL。