Jump to content

AJAX to replace the use of header("Location: ")


jBooker

Recommended Posts

I'm VERY VERY new to AJAX, so please bear with me.

 

Currently I'm working on a sort of CMS using PHP & MySQL for an MMORPG where users login and edit their characters and accounts.

My problem is that every time the user submits a form, to update their character stats, or clicks a link, to change their characters job, the script basically updates the database and then I use header("location: ") to send them right back where they were so the information they just updated in the database is displayed on the page or to display an error.

 

I was wondering if there is a way, or if it would be a better practice, to use AJAX to submit the form/link, update the database, and display the updated database information and error message to the user all in one go. Without the need for header();.

 

 

A simple example script would help me understand, if you don't mind.

Yes it is possible, but - in my opinion (and many others) - using AJAX (i.e. JavaScript) as the only means of doing this would be bad practice. You would be preventing the use of your site to anyone without JS enabled. Plus, you could run in to incompatability issues between how different browsers parse that JS code.

 

That being said, I would say that implementing an AJAX solution would be a good "additional" feature. In other words, the page should work without JS enabled through normal means of a form POST but, if JS is enabled, then utilize AJAX.

 

There are literally hundreds of tutorial on the net about AJAX. Trying to teach someone in a forum post would not make sense.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.