AJAX更新到表单后缺少POST参数


POST parameters missing after AJAX update to form

我有一个使用PHP&原型JS。我有两个链接的选择框,它们构成了一个更大表单的一部分。当用户更改第一个选择框中的值时,会触发Prototype Ajax Updater请求,以获得要在第二个选择框显示的值列表:

landlordId = $F('landlord_id');
branchId = $F('branch_id');
new Ajax.Updater('landlord_branches_div', baseUrl+"/landlord/getLandlordBranches", {
    method:'post', postBody:'landlord_id='+landlordId +'&branch_id='+ branchId,
});

这将返回一个填充到第二个选择框中的HTML块,例如(甚至可以看到这是通过Firebug返回的):

<select name="branch_id" id="branch_id" >
    <option value="all" selected="selected">All Branches</option>
    <option value="99" selected>HORDEN</option>
</select>

然而,当表单在上面的ajax请求之后提交(通过常规表单提交)时,帖子中缺少branch_id(如第二个选择框中所设置的)。如果加载的初始页面只是在没有触发第二个选择框上的任何ajax更新的情况下提交的,那么它就会出现在帖子OK中。

具有讽刺意味的是,它在IE中运行良好,但在Chrome或Firefox中不起作用。

如果有人能阐明这一点,我将不胜感激。

提前谢谢。

尝试:

    landlordId = $F('landlord_id');
branchId = $F('branch_id');
new Ajax.Updater('landlord_branches_div', baseUrl+"/landlord/getLandlordBranches", {
    method:'post',
    parameters:{ landlord_id: landlordId, branch_id: branchId}
});

如果我没有弄错,所以你有两个选择框,第二个选择框选项将由ajax更新程序填充,对吧?试试这个:

以下是html结构(您的结构可能与此不同):

<form id="form_id">
   <div id="landlord_div">
       <select id="landlord_id" name="landlord_id" onchange="ajaxcall()">
           <option value=1></option>
           <option value=2></option>
       </select>
   </div>
   <div id="landlord_branches_div">
   </div>
</form>

只需确保您的元素位于Form元素下即可。下一个是ajax更新程序脚本:

<script type="text/javascript">
    var ajaxcall = function() {
       new Ajax.updater('landlord_branches_div', 'your_ajax_url', {
            method:'post',
            parameters:'landlord_id='+$F('landlord_id'),
       });
    }
</script>

由于这个ajax调用用于显示第二个选择框(分支选择器),因此不需要在那里发布branch_id。让我知道这是否适合你。