PHP AJAX表单没有发布到PHP

时间:2011-12-01 12:19:52

标签: php ajax

表单包含一个更改下拉菜单,它应该使用ajax从数据库中获取值并使用复选框显示该复选框。 up up here wking good,当我提交表单时,复选框值不会被发布。

<form name="test" >

<tr>

    <td align="left"><b>System :</b> </td>


    <td align="left">

  <select name="system" size="1" onchange="regionsa(this.value);" > 

<option value="0">Select a System</option>

<?php // Retrieve all the announcement types and add to the pull-down menu.
$q = "SELECT * FROM System";    

$r = mysqli_query ($CARE_dbc, $q);


while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {


 // $sys_name =  $edit_menu['system'];




?>
<option value="<? echo $row[1];?>" <? if($row[1]==$edit_menu['system'])

  {
  echo $selec = "selected";
  }?> >

<? echo $row[1];?>
</option>
<? }?>
</select>
  </td>
</tr>
 <tr>

    <td align="left">
<b>User Type :</b> </td>

    <td align="left" ><span id="sant">


<?php // Retrieve all the announcement types and add to the pull-down menu.
$qUTdd = "SELECT * FROM `UserType`";    
$rUTdd = @mysqli_query ($CARE_dbc, $qUTdd); 
while ($rUTddrow = mysqli_fetch_assoc($rUTdd)) 
{
    $utype_qr = mysqli_query($CARE_dbc,"SELECT * FROM `menu_users` WHERE `menu_users`.menu_id='".$_REQUEST['id']."'"); 
    //$ut  = mysqli_fetch_assoc($utype_qr); 


    ?>                                 
        <input type="checkbox" name="user_type[]" value="<? echo $rUTddrow['idUType'];?>"  <? while($ut  = mysqli_fetch_assoc($utype_qr))
        {
            if($ut['user_type']==$rUTddrow['idUType'])
            {
                echo "checked";
            }                     
        }?>  /> <?echo "<b>".$rUTddrow['userType']."</b>"; ?>
        <?
}
?>
    </span> 
    </td>
    </tr>
    <input type="submit" name="submit" value="Add" />
    <input type="hidden" name="submitted" value="TRUE" />
    </form >
    <script language="javascript">
    var http = createRequestObject();
    function createRequestObject()
    {
        var request_o; //declare the variable to hold the object.
        var browser = navigator.appName; //find the browser name
        if(browser == "Microsoft Internet Explorer"){
            /* Create the object using MSIE's method */
            request_o = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
            /* Create the object using other browser's method */
            request_o = new XMLHttpRequest();
        }
        return request_o; //return the object
    }
    function regionsa(stateid)
    {
        //alert(stateid);
        http.open('get','internal_request.php?id='+stateid);
        http.onreadystatechange = handleresponse;
        http.send(null);
    }
    function handleresponse()
    {
        if(http.readyState == 4)
        {
            var response = http.responseText;
            //alert(response);
            document.getElementById('sant').innerHTML = response;

        }
    }
</script>

Internal_request.php

<?php
if($_REQUEST['id']=='annmet' && isset($_REQUEST['id']) && !empty($_REQUEST['id'])) 
{
    $qUTdd = "SELECT * FROM annmet.`usertype`";    
    $rUTdd = @mysqli_query ($CARE_dbc, $qUTdd); 
    while ($rUTddrow = mysqli_fetch_assoc($rUTdd)) 
    {
        $utype_qr = mysqli_query($CARE_dbc,"SELECT * FROM CARE.`menu_users` WHERE CARE.`menu_users`.menu_id='".$_REQUEST['id']."'"); 
        //$ut  = mysqli_fetch_assoc($utype_qr);   


        ?>                                 
        <input type="checkbox" name="user_type1[]" value="<? echo $rUTddrow['idUType'];?>"  
            <? while($ut  = mysqli_fetch_assoc($utype_qr))
            {
                if($ut['user_type']==$rUTddrow['idUType'])
                {
                    echo "checked";
                }                     
            }?>  /> <?echo "<b>".$rUTddrow['UserT']."</b>"; ?>
            <?
    }
}
?>

1 个答案:

答案 0 :(得分:0)

AJAX生成复选框的名称是user_type * 1 * [],而原始复选框名称是user_type []。

编辑: 您没有提到Form元素的“method”属性的值。因此,此表单使用默认表单提交方法,即GET。因此,您不会获得$ _POST变量的任何数据。使用print_r打印$ _GET变量并检查。