Submit form info with jquery and return result without reloading?

AJAX stands for Asynchronous JavaScript and XML. That means that $. Post will actually return before the response is received (a callback function is later asynchronously called when it is).

Therefore, the form is submitted immediately To stop this, insert return false at the end of the submit event handler, which will stop the form submission. When the response arrives, decide if you want to submit the form the normal way. This code can be used to do so: Unbind the submit event handler registered earlier // so we do not make another AJAX request $("form.

Register"). Unbind('submit'); // Actually submit the form $("form. Register").submit() Of course, if you don't need to, you don't need the latter code Note: One thing I would recommend is disabling the button during the AJAX request.

This will ensure that when a user unnecessarily tries to "double-click" the button, that will have no adverse effect. One way to do this is using jQuery's one method which also avoids the need to use unbind : function submitButtonClicked() { $. Post(..., function( data ) { ... // Submit form if data is valid $("form.

Register").submit(); // Re-enable button if form was not submitted $("form. Register"). One('submit', submitButtonClicked); }, "json"); // Cancel form submission return false; } $("form.

Register"). One('submit', submitButtonClicked).

AJAX stands for Asynchronous JavaScript and XML. That means that $. Post will actually return before the response is received (a callback function is later asynchronously called when it is).

Therefore, the form is submitted immediately. To stop this, insert return false; at the end of the submit event handler, which will stop the form submission. When the response arrives, decide if you want to submit the form the normal way.

This code can be used to do so: // Unbind the submit event handler registered earlier // so we do not make another AJAX request $("form. Register"). Unbind('submit'); // Actually submit the form $("form.

Register").submit(); Of course, if you don't need to, you don't need the latter code. Note: One thing I would recommend is disabling the button during the AJAX request. This will ensure that when a user unnecessarily tries to "double-click" the button, that will have no adverse effect.

One way to do this is using jQuery's . One method, which also avoids the need to use unbind: function submitButtonClicked() { $. Post(..., function( data ) { ... // Submit form if data is valid $("form.

Register").submit(); // Re-enable button if form was not submitted $("form. Register"). One('submit', submitButtonClicked); }, "json"); // Cancel form submission return false; } $("form.

Register"). One('submit', submitButtonClicked).

Just for the curious: jQuery's api page for one(). – David Thomas Nov 13 '10 at 18:05.

You need to make sure data. Submit exists and the value equals "test". Try using alert/console.log.

EDIT: Had another look. Try amending your code like this: $("form. Register").

Submit(function(e) { e.preventDefault(); $. Post("register. Php", $("form.

Register").serialize(), function( data ) { if( data. Submit == "test" ) $("p#submit_error").slideDown(); }, "json"); }).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions