View Full Version : Ajax - Handling process scripts

02-22-2008, 11:12 PM
I understand how ajax sends a request to a server side script and how it gets a response.

A lot of my scripts are usually "process" scripts and follow this flow:

user_interface.php (form leads to process script)
process_data.php (script that processes form into database...)
user_interface.php (back to user_interface via header() in proccess_data.php)

I do this to keep file sizes down.

Anyway how would I go about getting ajax to handle that kind of a script? Do I need to rewrite my scripts to be included as apposed to separate files that redirect? I am also trying to keep graceful degradation in mind.

02-23-2008, 12:33 AM
What are you using the AJAX call for? The path to the server-side script that the AJAX code uses doesn't really matter.. just point it to the page that you're using to process the AJAX request.

02-23-2008, 01:24 AM
The only (good) peaceful degradation that I know of is to have Javascript intercept a normal form submission, and AJAX the form instead. But in some cases it's not really worth the time to have two methods.

Basically what you would have to do is write a javascript function to go through all of the forms elements and build a GET style URL with the data, (though use POST on large forms.) This can be complicated for people who don't know Javascript well because you run into select menus, and worse yet, radios and checkboxes. They aren't as simple a normal input.

Also know that you can't upload files through AJAX.

If you are trying to get a form to save to a database or session as the user fills it out for whatever reason, then AJAX is a good idea, but if your just trying to stop the page flicker during a normal page submission, its probably not worth your time.

02-25-2008, 06:37 PM
Also know that you can't upload files through AJAX.

Just thought i would point out that you could mimic Ajax when uploading files by using iframes. Once the iframe is finished uploading the file(s), you may refresh the container by calling the parent from with in the iframe.