I have been into web development with both client amd server side code, and have been using JavaScript Ajaxto receive and manipulate for data along with PHP scripts.

However, I noticed that websites like Google and Facebook use PHP forms instead of sending ajax requeststo PHP scripts.

What I wonder is that what is the advantage of direct PHP form submit over sending form data from a static HTML page to a PHP Script via JavaScript Ajax, especially from the UX and security point of view?

1 Answer 1


What are PHP forms? Do you mean HTTP POST requests (Wikipedia, MDN)?

Ajax will usually POST as well. The only difference is that Ajax runs in the background, and does not navigate to a new URL. That also answers the UX question: if the user intention is not to leave that page, a background request seems more sensible.

There are no special security considerations for either case. PHP can be used both securely and insecurely, but this does not depend on the type of request.

  • That's what I meant! Ajax goes in the background, PHP navigates to a URL. Do you really think both are equally Secure? Commented Nov 28, 2017 at 10:58
  • @MrigankPawagi To the server, both request are almost exactly the same (differing only in minor, sometimes undetectable details). To the client there is a difference, but this difference usually only shows itself in the different user experience. There might be security differences if the site is using a Content-Security-Policy which may restrict either or both mechanisms, but does not do so by default if the Ajax URL or form action URL are on the same domain.
    – amon
    Commented Nov 28, 2017 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.