Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between ajax and form submit

Tags:

ajax

forms

I just want to know what is the difference between sending parameter with ajax(post/get) to a servlet and sending them with "submit" .

Thanks for your help.

like image 390
kawtousse Avatar asked May 28 '10 17:05

kawtousse


People also ask

What is AJAX form submission?

AJAX form submitting allows you to send data in the background, eliminating the need to reload websites to see the updates. This makes the user experience much smoother.

What is the difference between POST and AJAX?

post is a shorthand way of using $. ajax for POST requests, so there isn't a great deal of difference between using the two - they are both made possible using the same underlying code.

Does AJAX require a form?

With AJAX, there is really no need to use a form - you can do exactly the same thing without navigating away from the current page (unless you then specifically code it to do so).

How Stop form submit in AJAX?

If you want to prevent the default post method for the form's submit button, I suggest you could consider using the event. preventDefault() method. More details, you could refer to below codes: <form id="user-form" method="post">


2 Answers

A standard form submit sends a new HTTP request (POST or GET) and loads the new page in the browser. In Ajax, the data is sent to the server (POST or GET) in the background, without affecting the page at all, and the response is then received by javascript in the background, again without affecting the page at all.

(The javascript can, of course, then use the data received from the server to update some of the page content.)

Ajax is generally useful where only a small section of the page content will change.

like image 131
TRiG Avatar answered Oct 04 '22 16:10

TRiG


Server side handling of both are exactly the same. The server is not concerned about how the post request is made.

The difference is in how the browser (client side) responds to both the actions. The browser usually decides to make a request for an entire page if it is a form submit; otherwise, it just updates a part of the page.

like image 23
Anoop Avatar answered Oct 04 '22 15:10

Anoop