开发者

difference between ajax and form submit

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

Thanks for your help.


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.


At the simplest, with ajax, you don't witness page refresh while submitting form data. And if you don't use it eg you use submit buttons, you witness page refresh. Both submit the data.


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.


From the servlet's point of view there is no difference. For the client, a submit will load a new page, while an Ajax request will parse the response with javascript code and act accordingly.


The form submit will reload the page that you are working on client side.,while in ajax call the call was made to server will not reload your client side page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜