我在ajax中有以下代碼。我將兩個參數$job_id
和q
傳遞到了一個名爲interview.php的頁面,但是。但是,該頁面給我的警告是$job_id
未定義。我不知道如何使用AJAX POST或GET多個變量。從Ajax向PHP傳遞數據
我的AJAX文件是:
<script>
function showSuccess ($getid,str) {
var job_id= $getid;
var resp;
if (window.XMLHttpRequest) {
resp = new XMLHttpRequest();
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var data = "job_id="+job_id
xmlhttp.open("POST",
"interview.php?q="+str);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(data);
xmlhttp.onreadystatechange =
function display_data() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
} else {
alert('Request not successful.');
}
}
}
</script>
interview.php:
<?php
$q = intval($_POST['q']);
?>
<?php
$getid = $_POST['job_id'];?>
<?php
include('includes/conn.php');
$row="SELECT idNo,id,name,jobTitle,SUM(points) AS total FROM shortlist WHERE job='$getid' GROUP BY id ORDER BY total DESC LIMIT $q";
$query=mysqli_query($conn,$row) or die(mysqli_error($conn));
while($row=mysqli_fetch_array($query))
{
echo $row['name'];
}
mysqli_close($conn);
?>
'var job_id = $ getid;'是否有效? –
運行的腳本是'else alert('請求不成功'); }'在警告框中單擊確定後,我收到一條警告:q未定義索引 – Colo
請嘗試....數據:{para1:value1,para2:value2} – user1844933