我在我的網站的其他地方實施了相同的設置,但無法弄清楚爲什麼這次不工作。Php未收到來自JavaScript的信息
當用戶點擊接受按鈕時,它會調用一個JavaScript函數acceptOrder(orderID),它將orderID傳遞到php頁面以更新db中的記錄。
orderID在JavaScript中被分配好,但它沒有到達php。 POST上的Var_dump不顯示任何內容,$ _POST('orderID')也不顯示。我甚至嘗試發送一個整數到PHP的情況下,有問題的變種,但它沒有任何區別。
的js
function acceptOrder(orderID) {
var orderID=orderID;
console.log("assigned: "+orderID);
var xmlhttp;
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
// code for IE6, IE5
else
{
xmlhttp=new ActiveXObject("Microsoft. }
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
console.log (xmlhttp.responseText);
}
}
xmlhttp.open("POST","acceptorder.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-rule encoded");
xmlhttp.send(orderID);
console.log(orderID+" sent");
//location.reload();
//console.log("reload");
}
腓
<?php
require_once("config1412/class.shop.php");
session_start();
$shop = new SHOP();
echo var_dump($_POST);
//$orderID = $_POST['orderID'];
//echo "orderId var = ".$orderID."<br/>post ".$_POST['orderID'];
//$shop->acceptOrder($orderID);
?>
不用說,我已經搜查有關,並沒有看到其他地方的任何解決方案。
非常感謝
你有沒有得到任何錯誤? –
我已經發布了這個來自手機的內容,並刪除了部分圍繞微軟的js,所以忽略了這一點。 – Paul
@HappyCoding沒有錯誤 – Paul