Search code examples
ajaxjqueryajax-forms

How does ajax form submission work?


I know how to use ajax for submitting a form and all. What I am concerned about is, what is actually happening in the background when a form is submitted via ajax.

How are the values transferred? Encrypted or not? And what is the need of specifying submission type, I mean get or post, if the URL is not showing the form fields?

Edit: Found this on w3schools:

  • GET requests can be cached

  • GET requests remain in the browser history

  • GET requests can be bookmarked

  • GET requests should never be used when dealing with sensitive data

  • GET requests have length restrictions

  • GET requests should be used only to retrieve data

  • POST requests are never cached

  • POST requests do not remain in the browser history
  • POST requests cannot be bookmarked
  • POST requests have no restrictions on data length

How do these apply to ajax form submission?


Solution

  • Basically, when you Ajax-submit a form, it is doing exact same thing as what would happen when you as a user GET or POST submit a form - except that it is done in an asynchronous thread by the browser - i.e. called XMLHttpRequest.

    If you submit form as a GET request, all of the form values are stitched together as parameter strings and appended to the URL (form's ACTION URL) - prefixed by a ?. This means anyone who can intercept that communication can read the submitted form data even if request is sent to a HTTPS URL. The POST method sends form data as a separate block (from the URL) and if URL is HTTPS then form data gets encrypted.

    It looks like you are just starting out in the world of web development - welcome to the world of programming. I would recommend reading up on some good web development/programming books (I don't want to promote any particular book here). Amazon may help suggest few good ones under "Web Development" kind of search terms.

    Also, I suggest that you read up a little on GET vs. POST by googling for it (I can only include one or two links - google will show you hundreds).