通过对话框提交的表单再次打开对话

[英]Form submitted via dialog opens dialog again


I have a form in a jquerymobile dialog box that I am submitting via jQuery Ajax.

我在jquerymobile对话框中有一个表单,我通过jQuery Ajax提交。

Currently my problem is that once the form is submitted the same dialog box is opened again on top of the original dialogbox.

目前我的问题是,一旦提交表单,将在原始对话框的顶部再次打开相同的对话框。

So that my url reads before submission:

所以我的网址在提交前阅读:

url/index.php#&ui-state=dialog

and then after submission:

提交后:

url/index.php#&ui-state=dialog#&ui-state=dialog&ui-state=dialog

Has anyone ever encountered something like this before?

有没有人曾经遇到过这样的事情?

[edit added code example]

[编辑补充代码示例]

$(function(){
    $("#form").submit(function(e){
        e.preventDefault();
        var dataString = $("#form").serialize();
    errorInput = $("input[name=valOne]#valOne").val();
        $.ajax({
            type: "GET",
            url: "formHandler.php",
            data: dataString,
        dataType: "text",
            success: function(data){
            if(data.toLowerCase().indexOf("error") >= 0){
                alert(data);
                $(".ui-dialog").dialog("close");
                $("#valOne").val(errorInput);  //the reentering info so user doesn't have to
            }else{
                    $(".ui-dialog").dialog("close");
                    location.href="index.php";
            }
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert(thrownError);
            }
        });
    });
});

4 个解决方案

#1


0  

  1. You can set your own handler on form with this submit
  2. 您可以使用此提交在表单上设置自己的处理程序

  3. Use two forms for page and for your dialog window.
  4. 对页面和对话框窗口使用两种形式。

#2


0  

Have you tried using $.mobile.changePage("url here") instead of location.href? More details here http://jquerymobile.com/test/docs/api/methods.html

您是否尝试过使用$ .mobile.changePage(“url here”)而不是location.href?更多详情请访问http://jquerymobile.com/test/docs/api/methods.html

#3


0  

Would it not be easier to just refresh the page with JS instead of loading it again? It might be calling the dialog functions twice.

用JS刷新页面而不是再次加载它会不容易?它可能是两次调用对话框函数。

#4


0  

I had similar problem with forms. I decided to use <div data-role="fieldcontain"> instead. Now it works good with no "refresh effect". In this case you shouldmake your own message instead of .serialize.

我的表格有类似的问题。我决定改用

。现在它运行良好,没有“刷新效果”。在这种情况下,您应该使用自己的消息而不是.serialize。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/11/04/bdd0b702c3d64350f3eb5b4124af6c18.html



 
  © 2014-2022 ITdaan.com 联系我们: