views:

31

answers:

5

I'm developing a web site, which would make use of PHP, Javascript (JQuery) and use AJAX to connect the two. My question is, how should the coding process go.

I know that Javascript is supposed to be used as an extra kick, and should not be relied upon because it can be turned off. So, should I code the entire site in PHP, and then after all of that is done, add the JQuery code, or should I do both side by side?

A: 

If you are creating a Rich Internet Application than Javascript/Flash/Silverlight will become a requirement of the user in order to use your website. In that case you should perform a check to ensure the user has the correct plugin or javascript enabled. Otherwise display a page which states your site requires it, etc.

If you're just trying to use JavaScript to enhance your site but without it adding a ton of development than the backend would be developed first or if you need to support a large client base then different versions of your site could be made to support JavaScript and non-JavaScript users.

David Young
+1  A: 

If you decide to use AJAX as a core part of the site then you are basically excluding people without javascript which depending on your application can be a legitimate design decision. If you choose to do that then you should check if the user has JavaScript and warn them if they do not.

If you are requiring JavaScript you can develop with it simultaneously with the development of your server side code PHP code. If not, and JavaScript is just a UI enhancement it should be added in later.

Either way validating user input should always also be done on the server side in addition to the client side. All security related code should be only on the server side.

Adam
A: 

If you want your site to work even if Javascript is disabled, I would develop the site with PHP first and then add your Javascript enhancements. For example, on one site I developed, there is a calendar that lists upcoming events. When the user clicks on that event, a colorbox will appear and the details of that event will be loaded into that colorbox using AJAX. If Javascript is disabled, clicking on the event will just take the user to the event's page.

Cliff Clavin
A: 

I think it depends on the approach you take as a programmer.

If you take a top-down approach and start from the user interface and its features, then start from the Javascripts and HTML markup. In the process you can find out how your server API should respond.

If you take a "server capabilities" approach and implement what you can do in the server, then obviously you start implementing that part first. Then you'll continue with the markup and client javascript code, and adapt it to the available APIs that you built. (And probably, in the process, adapt them too).

In both cases, a bit of a design on paper wouldn't hurt.

Of course, as other people have answered, it also greatly depends on how extensive your javascript interface is, how much burden it takes away from PHP, and if you intend to provide an HTML-only interface where the PHP would need to do much of the work.

For instance, let's say you have a table in your code and you want the user to allow to sort it by different columns. This can be done in Javascript, and can be done in PHP, and it can be done in both. It's up to you and your decisions.

Avel
A: 

If you're planning with jQuery and Ajax in mind then JavaScript off would be almost a completely separate project. However if that is the case, I'd recommend taking the following steps.

  1. Develop the data access and business logic layers.
  2. Build the PHP UI layer w/ full page reloads, etc.
  3. Build an API over the DAL and BL that can be called from JS.
  4. Build the jQuery / Ajax UI from the ground up.

I'm skeptical about the pure server-side UI implementation though, and I'd go about it only if your user base will likely prefer that over the now mainstream JQuery based one.

Dan Stocker