Ajax表单提交。表单提交两次表单、两次、Ajax

由网友(罗密欧煮伱爷ぃ)分享简介:我正在使用CakePHP在我看来,我有一个Ajax提交按钮的形式。我渲染它使用了蛋糕的帮手。 I am working with cakePHP and in my view I have a form which has an ajax submit button. I rendered it using the...

我正在使用CakePHP在我看来,我有一个Ajax提交按钮的形式。我渲染它使用了蛋糕的帮手。

I am working with cakePHP and in my view I have a form which has an ajax submit button. I rendered it using the cake helpers.

    <form method="post" class="form-class" id="form-id" name="form1" style="display: none">
                *[content for the form]*
                    <?php
                    echo $ajax->submit('Ok',
                            array(
                                       'id'=> 'submit1',
                                        'url'=> array('controller'=>'c','action'=>'action1'),
                                        'complete'=> 'jsfunction()'

                                ));
                    echo $form->button('Submit',array('id'=>'cancel','value'=>'Cancel','onClick'=>'clickCancel()'));
                    ?>


</form>

当我点击提交,控制器动作被调用两次。我搜索stackOverlow如果存在这个问题,但没有找到一个有效的解决方案。有没有语法错误。

When I click submit, the controller action is called twice. I searched stackOverlow if this question existed but couldn't find a valid solution. There are no syntax errors.

帮助将是非常美联社preciated。谢谢你。

Help will be really appreciated. Thanks.

推荐答案

这听起来像AJAX事件处理程序不阻止的默认行为。 尝试内嵌设置窗体的onsubmit行为,以prevent它(蛋糕的助手完成):

It sounds like the ajax event handlers aren't blocking the default behaviour. Try setting the form's onsubmit behaviour inline to prevent it (as cake's helper does):

<form onsubmit="event.returnValue = false; return false;" method="post" class="form-class" id="form-id" name="form1" style="display: none">

我建议检查出的表单助手以解决此一些有用的快捷键。

I recommend checking out the FormHelper for some useful shortcuts around this.

阅读全文

相关推荐

最新文章