The form submitted through the dialog box opens the dialog box again.

I have a form in the jquerymobile dialog that I submit via jQuery Ajax.

My problem now is that after submitting the form, the same dialog box reopens on top of the original dialog box.

For my url to read before submitting:

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

and then after sending:

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

Has anyone ever encountered anything like this before?

[edit added sample code]

 $(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
source share
4 answers
  • You can set your own form handler using submit
  • Use two forms for the page and for your dialog box.
0
source

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

0
source

Isn’t it easier to just refresh the page with JS and not load it again? This can invoke dialog functions twice.

0
source

I had a similar problem with forms. Instead, I decided to use <div data-role="fieldcontain"> . Now it works well, without the “update effect”. In this case, you should make your own message instead of .serialize.

0
source

Source: https://habr.com/ru/post/1443987/


All Articles