xmlHTTPrequest POST无效

时间:2013-06-12 12:21:58

标签: php post xmlhttprequest

我有xmlHTTPrequest GET脚本工作正常,但由于服务器问题,我不得不将其更改为POST方法。 我无法获得$ _POST变量中的值。需要帮助来查看javascript是否正确。

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 &nbsp;</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'");

    ?>

1 个答案:

答案 0 :(得分:0)

试试这个

    <?php
    $q2=$_POST['q2'];

    include_once 'db.php';
//'{$q2}' instead of just '$q2'
    $thisquery = "UPDATE RATEMASTER_draft SET Prod_desc='{$q2}'";
    mysql_query($thisquery);

    ?>