我有运行正常的 xmlHTTPrequest GET 脚本,但由于服务器问题,我不得不将其更改为 POST 方法。我无法获取 $_POST 变量中的值。需要帮助以查看 javascript 是否正确。
xmlHTTP请求文件:
<?php include 'accesscontrol.php'; ?>
<?php
include_once 'db.php';
?>
<html>
<head>
<title>POST</title>
<script type="text/javascript">
function showprodes(str2)
{
var q2 = str2;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "http://www.amg.in/amogtst/rateprod.php";
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(q2);
}
</script>
</head>
<body>
<?
$result2 = mysql_query("SELECT Prod_desc FROM PRODMAST ORDER BY Prod_desc");
echo "<form name='f1'>";
echo "<table width='730' border='0' align='center' cellpadding='0' cellspacing='1'>";
echo " <tr>";
echo " <td colspan='3'>";
echo " <span class='style3'>Gas Type </span> <select name='Proddesc' onchange=\"showprodes(this.value);\"><option value=0>Select a Product</option>";
while($nt2=mysql_fetch_assoc($result2))
{//Array or records stored in $nt
echo "<option value='$nt2[Prod_desc]'>$nt2[Prod_desc]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
echo " </td>";
echo " </tr>";
echo "</table>";
echo "</form>";
?>
</body>
</html>
第二个脚本根据用户从第一个 php 中的选择更新表:rateprod.php 文件:
<?php
$q2=$_POST['q2'];
include_once 'db.php';
mysql_query("UPDATE RATEMASTER_draft SET Prod_desc='$q2'");
?>