2 回答
TA贡献1836条经验 获得超4个赞
尝试与此更改javascript部分(它将引发消息框,并且您将看到脚本在结束前失败):
<script type="text/javascript">
function getlocation(locationarea) {
var xhttp = new XMLHttpRequest();
var url = "dynamicdd.php";
var data = new FormData();
data.append('SearchValue', locationarea);
xhttp.open('POST', url, true);
xhttp.send(data);
alert("*step 1*");
xhttp.onreadystatechange = function() {
alert("*step 2*");
if (xhttp.readyState == 4 && xhttp.status == 200) {
alert("*step 3*");
alert(xhttp.responseText);
document.getElementById("locationbycountry").innerHTML = xhttp.responseText;
}
}
alert("*step 4*");
}
</script>
<?php
if($_POST['SearchValue']){
$host = "localhost";
$username = "root";
$password = "";
$db = "";
$conn = mysqli_connect($host, $username ,$password, $db);
$choice = $_POST['SearchValue'];
$sql = "SELECT * FROM Locations WHERE country = '$choice'";
echo $sql;
}
else {
echo "value is not posted";
}
?>
添加回答
举报