1

I am currently working on a site that heavily uses AJAX. I have a page that when called renders the basic HTML and then uses AJAX to get the data that the pages needs and then renders the rest of the page. There is no user interactivity on the page.

I was of the belief that AJAX should only be used it there was going to be some user interactivity of some sort?

As the page that is being called knows exactly what data is required at the point of call that the complete page should be rendered. There is no form on this page, no user interactivity - as far as the user is concerned it's just a static page.

To put it in context - there is a search page that provides a list of results, and the user clicks on the result to get a details page related to that result. This is not a SPA - the detail page opens up in a new browser window/tab - and that will not change. The detail page has no interactivity.

I think that the detail page should be generated on the server with no use of AJAX. What would you advise in this situation?

  • While I agree with you that it looks useless now, if the general pattern of the site is that all data is loaded via AJAX, (usually after some user interaction like button-clicking) then it would be best to have this page operate the same way, even though the user does not take any action. Furthermore, once the data is available through AJAX for this page, other pages could just make the same AJAX call if they ever want that data too. – Graham Jul 25 '16 at 14:59
  • If your app is coded the right way then this data should be reusable regardless of how it is sent to the browser, and if it is needed for some reason via AJAX in the future then you can just wrap it with a webservice or REST service. I have had issues in the past where a decision was made to expose everything via webservice and then access that data only by webservice calls - it cause unnecessary extra calls to the webserer and it caused a bottleneck - what should have been one call to load the page became 3-4 server calls which increased the overall processing time by a considerable amount. – James Culshaw Jul 25 '16 at 15:03
1

AJAX has legitimate non-interactive uses:

  • For example, Stackexchange notifies you of comments, badges earned and reputation change without you needing to refresh the page. Also a message stating that a question with new activty exist is shown.

But:

  • If the data will change when the user is staring at it non-interactively, and it's updated using AJAX, you should show a message/notification stating so (as StackExchange does).

In the other hand:

  • Even if the page is dynamically generated from a database, but the user doesn't need to partially update a section of the screen, the use of AJAX is an overkill.
0

Using AJAX is not just for interactivity. Displaying new data and updating a section of the page is a valid approach. Thus, this is IMHO a legal use case.

There is an aspect of the described behavior which impacts usability. That is the user sees an empty page and then out of a sudden data appears. This is solvable using loaders or pre-rendering and attaching AJAX loading.

Edit in response to comment: If the data is never changed, the page is static, well then there is no real need for AJAX altogether. Maybe the data shown is used somewhere else, too. In an AJAX manner. Then someone took the easy way out. Took existing code instead of rewriting it server side. Even then, this might be a good solution when viewed from a project manager's perspective.

Just to make it clear: this answer is an opinion or at least close to it and there is no certain truth.

  • But if the page never changes its content beyond the initial load why should I use AJAX to get that data? Surely there is an overhead of making the second call to the server when I can just get the data during the initial page load as the data that is required is known at that time. – James Culshaw Jul 25 '16 at 13:12
  • @JamesCulshaw Amended my answer – Sascha Jul 25 '16 at 15:04
  • in this case the data wasnt used elsewhere - a decision was made that ALL webpages would just be barebones HTML and that all content that was to be got from a database was to be done via AJAX - regardless of whether the data required was known at page request time or later. What hits me is that in this case where the url maps to a fixed content for the page, without the AJAX call, ASP.NET caching can be taken advantage of, but with the use of AJAX calls it can't – James Culshaw Jul 25 '16 at 15:10
  • 1
    @JamesCulshaw With this setup I would agree that AJAX is not required even adds too much overhead: additional steps until page is done and more complexity that has to be maintained – Sascha Jul 25 '16 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.