Submit A Form Via Ajax Using Prototype And Update A Result Div October 28, 2022 Post a Comment I'm wondering how can I submit a form via Ajax (using prototype framework) and display the server response in a 'result' div. The html looks like this : Solution 1: Check out Prototype API's pages on Form.Request and Event handling. Basically, if you have this: <form id='myForm'> .... fields .... <input type='submit' value='Go'> </form> <div id='result'></div> Copy Your js would be, more or less: Event.observe('myForm', 'submit', function(event) { $('myForm').request({ onFailure: function() { .... }, onSuccess: function(t) { $('result').update(t.responseText); } }); Event.stop(event); // stop the form from submitting }); Copy Solution 2: You first need to serialize your form, then call an Ajax Updater, using POST options and pass it the serialized form data. The result will then appear in the element you sepcified. Solution 3: You need to return the value false from the ajax function, which blocks the standard form submit. <form id="myForm" onsubmit="return myfunc()" action="/getResults"> function myfunc(){ ... do prototype ajax stuff... return false; Copy }Baca JugaChange Data-attribute On Click Of Html ElementsToggling(or Flashing) A Particular Cell In A Table For Some Time FrameClickable Html Table Rows That Post To A Php Popup Window Using onsubmit on the form also captures users who submit with the enter key. Solution 4: You need to stop the default action of the onsubmit event. For example: function submit_handler(e){ Event.stop(e) } Copy More info on stopping default event behavior in Prototype » Share You may like these postsJavascript File Dependencies - Selective Load Resource Files & Prevent DuplicatesJavascript Class Property Not Set In Success Function Of Ajax CallMVC 4 Ajax Requests - Referencing A Javascript FileGET Return Value From Python Via Javascript Ajax Post a Comment for "Submit A Form Via Ajax Using Prototype And Update A Result Div"
Post a Comment for "Submit A Form Via Ajax Using Prototype And Update A Result Div"