tags:

views:

114

answers:

2

Hello,

I have a page with 3 layers, one for navigation, one for database records and one for results. When I click on a database record, the results are displayed in the result layer via ajax. For navigation, the links will simply be different queries. I am wondering if it would make sense to have each different query be sent as ajax data and palced into the records layer, or rather to have the query appended to the php file each time. Which is the more efficient approach?

A: 

I think you question is quite unspecific and confusing. What is "appended to the php file"?

Are you really concerned about efficiency? I mean, how fast should the results be displayed? Or are you concerned about the server workload?

Have you read this tutorial? Prototype introduction to Ajax I think it should answer most of your questions and give enough example code to continue.

Ralf
I mean should I have file.php?queryword=item as opposed to each link executing a sepearte php file to return the data to the generated html file. I am equally concerned with server workload and responsivness. I cannot use prototype as my application has been written from scratch.
Joshxtothe4
+1  A: 

Well, sending a different AJAX request will be recommended as per my point of view. As

  1. Performance wise, it will rather reduce the response times, as only the POST data is sent and databytes recieved. The page can then format it, one it receives an XMLHttpResponse

  2. Security wise : I prefer using POST than GET as it gives at least some opaqueness as to what is being passed as a parameter and not anyone can just edit the url and play around. Plus, you don't have the URL length restriction while passing parameters in POST.

So, i'd say fire an XMLHTTPRequest each on each link and display the response in the Results layer (pane/div) on the page.

Mohit Nanda
Thanks very much for your reply. I had one slightly OT question, I was just wondering why ajax must use xml, why there is just no HTTPRequest Object? My current JS code is at http://www.nomorepasting.com/getpaste.php?pasteid=22159, would it be possible to use that file, or would I need something sep
Joshxtothe4
Well... for this WHY.. i believe I don't have a reason. But X in AJAX stands for XML, and so only the architects of AJX may answer this accurately. :)
Mohit Nanda
Also, would this make a difference for performance as only the links would be additional reloaded each time without ajax? can my javascript file be adapted to multiple requests?
Joshxtothe4