I’m writing a script that will send user details to a PHP script via AJAX. Currently the PHP script works fine. No problems there. I’d like to know how the callback should be handled.
Should I point it to the existing PHP script, or should I create a new file specifically for processing AJAX requests (creating redundant code)?
$.ajax({
type: 'POST',
url: 'existing-script.php',
// OR url: 'callback.php',
success: function(feedback){
alert(feedback);
}
EDIT:
The PHP currently inserts the users personal details (name, etc.) as well as uploads images. It’s a wizard that builds an account once the user signs up. This action is shared between the AJAX (Wizard) and the standard “Edit your profile” page
According to REST principles, URIs are names for resources. Client side, you should use the same URI only when accessing the same resource. Ask yourself what resources the site makes available.
Server side, you can map a URI to any script when handling a request. Often, the mapping is 1-1 (a separate script for each URI) or all-1 (where a single script serves as the entry point to handle all requests) for simplicity’s sake, but you could use some other mapping, depending on what makes sense for your project. If having one script handle user profile updating and image upload is a good design, go with it. As for what counts as “good design”, it’s a matter of picking an architectural pattern that promotes your project’s development goals (e.g. short development time, allows team to work effectively, easy maintenance) and sticking to that pattern.