views:

241

answers:

2

Hi All,

I'm building a site using ajax and am trying to decide where to put the files that supply the data for the ajax requests.

For example, I am going to have a .js file that can be included in a page that will create country/state select boxes. I will have the .js file under /inc/js.

However, I am not sure where I want to put the ajax file that supplies the state data based on the country selected. I could put it next to the file it supports, make a folder for ajax data request files, etc.

What do you do to keep your ajax requests organized by file?

A: 

Create a separate site (same server or on another) that will serve only as a REST service generating output for your requests. When you work with AJAX you are in essence consuming published web services.

Nikola Stjelja
+2  A: 

If you're planning on using a Model-View-Controller architecture, then you would place your ajax handler scripts where you maintain the remainder of the your controller scripts for the site.

For example:

/application
    /default
        /controllers
            index.php
            index.ajax.php
       /views
         index.tpl
         index.ajax.tpl
    /admin

Using a model like this, it leaves you free to decide whether it makes more sense to create handler scripts for your ajax calls or to integrate the handler scripts for your ajax calls into the other, existing controller scripts.

Noah Goodrich