[英]xmlHTTPrequest POST not working
I had xmlHTTPrequest GET script which was working fine, but because of server issues I had to change it to POST method. 我有xmlHTTPrequest GET脚本,该脚本运行良好,但是由于服务器问题,我不得不将其更改为POST方法。 I am unable to get the value in $_POST variable. 我无法获取$ _POST变量中的值。 Need help to see if the javascript is correct. 需要帮助以查看JavaScript是否正确。
xmlHTTPrequest file: xmlHTTPrequest文件:
<?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>
second script which updates the table as per the user selection from first php: rateprod.php file: 第二个脚本,根据用户从第一个php:rateprod.php文件中选择的内容来更新表:
<?php
$q2=$_POST['q2'];
include_once 'db.php';
mysql_query("UPDATE RATEMASTER_draft SET Prod_desc='$q2'");
?>
try this 尝试这个
<?php
$q2=$_POST['q2'];
include_once 'db.php';
//'{$q2}' instead of just '$q2'
$thisquery = "UPDATE RATEMASTER_draft SET Prod_desc='{$q2}'";
mysql_query($thisquery);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.