Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronous form to Asynchronous form submit

 
Swapnika Mishra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a button on UI which adds messages and when the user clicks on it the form gets submitted, meanwhile the user is clicking on refresh(F5) multiple times which is causing the same message to be displayed multiple times. To resolve this , I am converting the form from a synchronous submit to Asychronous but it is still not working. Please assist. Below is the code:

Code before:
<td><input class="buttonred" type="submit" value="Confirm Add" name="submit_message"></td>

<s:form action="upd-message" method="POST" validate="true" onsubmit="validateMsg();return false;" enctype="multipart/form-data">


function validateMsg() {
var frm = document.forms["upd-message"];
frm.actionType.value=message;
if (message == "submit_message") {
if (frm.subject.value == "" || frm.contnt.value == "") {
alert ("Please fill in Subject and Message");
return false;
}
}

frm.submit();
}


Code After:

<td><input class="buttonred" type="button" value="Confirm Add;" onclick="jQuery.addMessage();" name="submit_message"></td>


In my jquery.js


jQuery.addMessage= function() {
var frm = document.forms["upd-message"];
if (frm.subject.value == "" || frm.contnt.value == "") {
alert ("Please fill in Subject and Message");
return false;
}

frm.actionType.value = "submit_message";
frm.submit();
};



 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35753
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a pattern called post redirect get. It starts out by submitting a POST which you are doing. Then instead of just returning the response, it does a redirect to a GET. Then when the user refreshes, he/she is only redoing that display rather than the whole updating operation.

I'm not clear on how asynchronous comes into your question. I don't see anything async in that code.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I describe that pattern in the bigger picture of web app structure in this article.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!