我无法发布ajax值

时间:2013-07-09 07:12:55

标签: php ajax post

我知道这可能是一个小问题,但我花了很多时间并没有找到任何解决方案。让我简要介绍一下我的问题.. 我有这个表格,我正在尝试为州,城市和城市制作一个下拉列表。通过ajax调用的区域,这是ajax调用的代码。

function getsstate(category_name) {     

        var strURL="state.php?sstate="+category_name;
        var req = getXMLHTTP();

        if (req) {

            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                    if (req.status == 200) {                        
                        document.getElementById('sstatediv').innerHTML=req.responseText;                        
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }
                }               
            }           
            req.open("GET", strURL, true);
            req.send(null);
        }       
    }
function getccity(subcategory_name) {       

        var strURL="City.php?ccity="+subcategory_name;
        var req = getXMLHTTP();

        if (req) {

            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                    if (req.status == 200) {                        
                        document.getElementById('ccitydiv').innerHTML=req.responseText;                     
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }
                }               
            }           
req.open("GET", strURL, true);
req.send(null);
        }       
    }

</script>

它的工作正常..见图像 enter image description here

现在我正在尝试将这些值插入到我的数据库中,但只有状态名称才会进入数据库。 我的表格是:

<form name="register" action="register_tuto.php" id="formID" method="post">
<select name="state" onChange="getsstate(this.value)">
    <option value="">Select State</option>
    <?php
    //database connection here
$q=mysqli_query($con,"select * from state where category_status='1'");
while($n=mysqli_fetch_array($q)){
echo "<option value=$n[category]>$n[category]</option>";
}
?>
 </select>

<tr>
 <td align="left" valign="top" style="font-size:13px;">City <span class="redtxt_01">*</span>
<div id="sstatediv"><select name="ccity" >
<option>Select City First</option>
</select></div> </td>
                </tr> 

<tr>
<td align="left" valign="top" style="font-size:13px;">Area <span class="redtxt_01">*</span>

</td>
<div id="ccitydiv"><select name="aarea">
    <option>Select Area First</option>
        </select></div>                         
</td>
</tr>

作为测试,我试图在register_tuto.php页面上打印这些值:

<?php
echo $a=$_POST['state'];
echo $b=$_POST['ccity'];
echo $c=$_POST['aarea'];
?>

这里只有国家价值回归......任何想法或帮助都会被高兴地接受。

0 个答案:

没有答案