1

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?

asked Nov 26, 2017 at 17:44

1 Answer 1

2

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.

answered Nov 26, 2017 at 17:54
2
  • 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. Commented Nov 28, 2017 at 12:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.