JavaScript AJAX Basics (retiring) jQuery and AJAX Posting Data with jQuery

Jose Morales-Mendizabal
Jose Morales-Mendizabal
18,451 Points

AJAX or PHP solution for posting data and staying on same page?

in AJAX basics, Dave McFarland shows how to post data from a form, and load in new HTML markup upon success, all without ever leaving the page.

Now, in "Building a simple PHP application" course (specifically in the last 3 videos of the Adding a contact form section), Andy Hoyt shows a pure PHP method to do the same. This server side method uses conditional statements to display markup depending on the $_SERVER variable status.

I want to implement this feature in a website I'm building. Which solution should I use? is there an advantage on using one over the other?


1 Answer

Stone Preston
Stone Preston
42,012 Points

I think you may have to use AJAX if you dont want to reload the page (I may be wrong). The PHP method you mention might not navigate away from the contact page, but when the form is submitted I think it has to reload the page.

In other words I think with AJAX you send a request to the server, it sends a response back and changes can be seen on the page, no refresh or reload of any kind takes place. With PHP you send a request to the server, it executes the conditional PHP code, then sends the response back and the page has to be reloaded for changes to be seen. So if you want your dynamic changes to be seamless and not require any reloading then you will need to use AJAX.