AJAX vs. Traditonal Forms

Finding the balance between AJAX and old style forms

Page 1 of 1

6 Replies - 1743 Views - Last Post: 03 July 2008 - 04:14 PM

#1 Mike007  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 332
  • Joined: 30-August 07

AJAX vs. Traditonal Forms

Post icon  Posted 30 June 2008 - 05:50 PM

Are there any drawbacks to using AJAX as opposed to the traditional way of using forms?

I'm just asking this since I'm new to the idea of AJAX but it allows me to do somethings that I wasn't able to do before(well at least not without a lot of workarounds). So since I'm not experienced with using AJAX technology, I decided to ask so of you guys for advice.

Is it a good idea to use AJAX to load a page (or part of it) in XML and convert it to HTML using Javascript, instead of just using a PHP template engine to render the page in HTML? Or maybe combine the two and use a template to load the HTML and a XML http request to update the page after certain events have been triggered and then transforming it to HTML again, which kinda creates a duplicate of a code that does the same.

For example: consider a php application that displays and manages pictures for a picture gallery. The application consists of 2 parts, one that manages the pictures (upload, delete, rename, ect..), and the other displays the pictures to the user. Lets assume that we already built the fist part, now we have to display the pictures to the user. We will use thumbnails to display the pictures and when a user clicks on the thumbnail he can view an enlarged version of the same picture and also navigate and see other pictures there. So to achieve that we need AJAX to get a list of all the pictures in an XML format. But, the thing is should we use AJAX to load the thumbnails as well? Or maybe just use a normal template to display thumbnails and AJAX to display the enlarged version of the pictures.

I hope this example clarifies it, I'm just trying to find the balance between AJAX and the old form approach. And these kind of applications are pretty common today.

Is This A Good Question/Topic? 0
  • +

Replies To: AJAX vs. Traditonal Forms

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4307
  • View blog
  • Posts: 12,088
  • Joined: 18-April 07

Re: AJAX vs. Traditonal Forms

Posted 30 June 2008 - 08:19 PM

Keep in mind that AJAX is most effective when it can ask for as little info as possible. The reason is performance. While you are making synchronous or asynchronous calls, large amounts of processing and fetching of data is going to slow down your interface. Sometimes it is better to let the user know that a new page must be fetched than to leave them wondering if clicking that button is actually doing anything. Because with AJAX you may leave the user wondering if any action was taken because it is currently waiting for some background data to be fetched.

So in your situation I would go with the mix of template for your thumbnails and then using AJAX for the large pictures. Remember that you can pull just the PATH to the enlarged graphic through AJAX and setting the <img src> to this new path will cause the browser to fetch the graphic, not AJAX. So in all reality AJAX is pulling over a simple string of text and the browser handles the rest. This should also download the large image as possible.

Hope this makes sense. :)
Was This Post Helpful? 0
  • +
  • -

#3 Mike007  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 332
  • Joined: 30-August 07

Re: AJAX vs. Traditonal Forms

Posted 30 June 2008 - 08:43 PM

Well I was also thinking of using an XML reply from the server rather than HTML use an XML file something like:
<?xml version="1.0"?>
<imageset num_images="25">
    <image>
        <src>pics/large/somepicture.jpeg</src>
       <width>1024</width>
       <height>768</height>
       <description>Some picture I took</description>
       <date>2008-05-12</date>
    </image>
   .
   .
   .
</imageset>



Is that the way to go about it?

And about the wait time, yeah it can be a problem but most sites put a "loading..." text or graphic to notify the user and remove it when a reply comes back from the server. But I know javascript is extremely slow in some cases that is why I was concerned.
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4307
  • View blog
  • Posts: 12,088
  • Joined: 18-April 07

Re: AJAX vs. Traditonal Forms

Posted 01 July 2008 - 12:19 AM

well if you want to pull a bunch of data across in an XML format sure. Just keep in mind that the more data you pull across the more you parse and the more you parse the slower things can get. So keep as much of it limited to the absolutely needed info and you will be fine and notice very little slow down.

Javascript performance is not a huge issue with this, it is the time it takes to contact the server, that server to put together the info and respond that will take way more time than javascript would.

Put a demo together and give it a test run and see what kind of performance you get. Then build on from there.

:)
Was This Post Helpful? 1
  • +
  • -

#5 Mike007  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 332
  • Joined: 30-August 07

Re: AJAX vs. Traditonal Forms

Posted 03 July 2008 - 03:47 PM

Oh, I see what you are saying. It's better to fetch the data in chunks rather than just all of it together. Because downloading the information about 250 pictures at once in an xml file can be a pain. So I better download it in say 5 pictures at a time in one xml file. Basically just like I would do with SQL LIMIT setting in PHP.

Thanks marty I didn't think about the size of the XML, always good to get the advice of an expert :). I thought I would get away without using a database this time lol, guess that wouldn't be a good idea to just open a folder in PHP and list all files in it, pull some more data out of the picture files and iron it to a nice XML. That was my first thought, now I think I will use a database so I can index the picture (and I will not save them as binary in the database that will be crazy, just their address). Ok so I guess I got to go to the drawing board :).
Was This Post Helpful? 0
  • +
  • -

#6 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: AJAX vs. Traditonal Forms

Posted 03 July 2008 - 03:55 PM

While the size of the database is a concern, you should also be thinking about the size of the actual data you're moving - in your situation, I would recommend retrieving only a single image at a time(when the large ones are displayed) versus retrieving any more than that. Ajax is great for small bits of data like URLs(as Martyr2 mentioned), or small amounts of XML - but you don't want to use Ajax for any more than you need to.
Was This Post Helpful? 0
  • +
  • -

#7 Mike007  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 332
  • Joined: 30-August 07

Re: AJAX vs. Traditonal Forms

Posted 03 July 2008 - 04:14 PM

Yeah that's what I meant, I want to get the URL among other data about a picture file, not the file itself. The file itself will be loaded using that data at a different point of time, or in other words after a user triggers an event that will cause the picture file to download. Sorry I didn't explain myself right before. Thanks for the reply tho :).

Maybe I should have used the word metadata?... Guess that would have made stuff more clear

This post has been edited by Mike007: 03 July 2008 - 04:16 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1