-2

I am trying to handle the complete event of submitting form. I prepare the form like this:

var _url="../ex/tem?sessionId="+sessId;
var form = document.createElement("form");
form.setAttribute("id", "myForm");
form.setAttribute("method", "post");
form.setAttribute("action", _url);
form.setAttribute("enctype", "multipart/form-data");

form._submit_function_ = form.submit;
var textName=document.createElement("input");
textName.setAttribute("type", "hidden");
textName.setAttribute("name", "textName");
textName.setAttribute("value", textName);
form.appendChild(textName);

document.body.appendChild(form);

and I submit it like this:

form._submit_function_();

How I can catch the complete event?

JJJ
  • 32,902
  • 20
  • 89
  • 102

1 Answers1

1

Possible Duplicate Of How do I capture response of form.submit

In general the action of "submit" will post the data to another page, hence it is more of a redirect as well.. There is no "after" event as such, well not that i am aware of..

You generally use something like ajax to post the data to another page, wait for the response data and then continue on your way.

With forms, something like jquery will simple grab all of the controls and save them as a array of values and post them while offering a response and error callback/event.

EDIT: As with the jquery way of doing it... (Example from Duplicate Page)

$('#myFormElement').ajaxForm({
    url : 'Page_That_Will_Send_A_Response.php', // or whatever
    dataType : 'json',
    success : function (response) {
        // The object of response is a PHP array or object normally.. easy to build
        alert("The server says: " + response);
    }
})

;

jQuery AJAX Information: http://api.jquery.com/jquery.ajax/

Community
  • 1
  • 1
Angry 84
  • 2,935
  • 1
  • 25
  • 24
  • I see this page before asking the question, and I am tried the suggested solution in it. but it does not work for me. – أسامة حمدان Feb 05 '15 at 08:59
  • Are you simply wanting to post form type data to another page and handle a response / complete event? If so can quickly edit/paste code for you. – Angry 84 Feb 05 '15 at 21:25