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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.