简体   繁体   中英

PHP Post vs JavaScript Ajax Request

I have been into web development with both client amd server side code, and have been using JavaScript Ajax to 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 requests to 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 ?

There is ZERO security benefit of using a form over using XMLHttpRequest. Anyone can go into their console and change anything they want with a form request just like they can change the XMLHttpRequest.

In the end they are both http requests sent over the wire. You can open up a terminal window and make http requests to any site, it really does not matter. That is why we always say validate your data on the server to make sure it is valid.

Why would someone use an HTML form over Ajax? Well it has worked for ages with and without JavaScript disabled. They want to send a user to another page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM