views:

206

answers:

4

As jquery ajax calls makes life really cool without a page refresh... But still interested to know some of the advantages and disadvantages of making ajax calls with jquery....

As i am using ajax calls for all my Add,Edit and Delete operations in my website it works pretty well as of now... Still knowing about the disadvantages would make life easier during deployment....

+1  A: 

PRO:

In many cases, related pages on a website consist of much content that is common between them. Using traditional methods, that content would have to be reloaded on every request. However, using Ajax, a web application can request only the content that needs to be updated, thus drastically reducing bandwidth usage and load time.

The use of asynchronous requests allows the client's Web browser UI to be more interactive and to respond quickly to inputs, and sections of pages can also be reloaded individually. Users may perceive the application to be faster or more responsive, even if the application has not changed on the server side.

The use of Ajax can reduce connections to the server, since scripts and style sheets only have to be requested once.[12]

State can be maintained throughout a Web site. JavaScript variables will persist because the main container page need not be reloaded.

CON:

> Owing to their dynamic nature, Ajax interfaces are often harder to develop when compared to static pages.

Pages dynamically created using successive Ajax requests do not automatically register themselves with the browser's history engine, so clicking the browser's "back" button may not return the user to an earlier state of the Ajax-enabled page, but may instead return them to the last full page visited before it. Workarounds include the use of invisible IFrames to trigger changes in the browser's history and changing the anchor portion of the URL (following a #) when Ajax is run and monitoring it for changes.

Dynamic web page updates also make it difficult for a user to bookmark a particular state of the application. Solutions to this problem exist, many of which use the URL fragment identifier (the portion of a URL after the '#') to keep track of, and allow users to return to, the application in a given state.

Because most web crawlers do not execute JavaScript code, publicly indexable web applications should provide an alternative means of accessing the content that would normally be retrieved with Ajax, to allow search engines to index it.

Any user whose browser does not support JavaScript or XMLHttpRequest, or simply has this functionality disabled, will not be able to properly use pages which depend on Ajax. Similarly, devices such as mobile phones, PDAs, and screen readers may not have support for the required technologies. Screen readers that are able to use Ajax may still not be able to properly read the dynamically generated content. The only way to let the user carry out functionality is to fall back to non-JavaScript methods. This can be achieved by making sure links and forms can be resolved properly and do not rely solely on Ajax. In JavaScript, form submission could then be halted with "return false".

The same origin policy prevents some Ajax techniques from being used across domains, although the W3C has a draft of the XMLHttpRequest object that would enable this functionality.

Like other web technologies, Ajax has its own set of vulnerabilities that developers must address. Developers familiar with other web technologies may have to learn new testing and coding methods to write secure Ajax applications.

Ajax-powered interfaces may dramatically increase the number of user-generated requests to web servers and their back-ends (databases, or other). This can lead to longer response times and/or additional hardware needs.

wikipedia.org

Kind Regards

--Andy

jAndy
Those all sound like advantages...
Mark
+2  A: 

The best use of AJAX is where it is used to send small payloads. Here is a simple example.

I load a page that contains information about stock. It has graphs, charts, company information and it also displays the share-price. Every 30 seconds, I make an AJAX request that gets the updated share-price and changes it on the page.

Without AJAX, I might decide to refresh the entire page every 30 seconds, but with AJAX, I can just make a lightweight request to get the tiny bit of information I need.

Using AJAX to submit forms isn't always the best bet. Asides from not really giving you a clear advantage over posting the form normally, you break conventions such as browser history (although some browsers now include JavaScript "states" as pages in the history).

When using AJAX, you need to handle the task of telling the user if something has gone wrong. You can do this with jQuery by specifying what should happen on error, but many people forget to do this and the end user is blissfully unaware of any problem.

Other issues to watch out for are any JavaScript errors that may prevent your events from firing - or if JavaScript is disabled, in either case ensuring that the form can submit normally before you add the AJAX code is the safest option.

Sohnee
+1  A: 

Well, jAndy seems to have the advantages nailed down, and you seem to be aware of the advantages already, or you wouldn't be using it.

The downside is that it mucks up your browser's back button if you're loading in entire pages (yes, this can fixed too via some more JS wizardry). But if your whole site relies on ajax, then it probably won't function with JS disabled. Also, it doesn't produce very nice URLs. If you want to link your friend to a specific page in an ajax-intensive site, and assuming you've done your JS wizardry so that this is actually possible (modifying the URL after the # character), it still has to load the main page first, and then wait for the JS to kick in before it can ajax-load in the content you're actually interested in. I find this actually gives slower perceived response time, which I don't like at all. I love ajax, but I don't like it for full-page stuff.

Mark
+1  A: 

Its long history of battles between browser and specification that end up in real mess. We as developer understand it when we realize that we are spending more time resolving cross browser specific issues instead of solving the programming business logic/problem.

+ve

  1. No cross browser pain
  2. U can trust that good developer have spent there time and energy making library
  3. U can focus more on actual problem and not on side effects
  4. API's are good. If someones tells UI developer that ajax, HTTP, JavaScrtip bla bla bla........ OFFFF simple function is always great Ajax.call(url, callbackfunction, param). That is all we are looking for most of the times.
  5. Great time saving :) and u can enjoy parties no late night work

-ve

  1. U will be playing on smooth surface and saving skin from headaches that are good for we as software engineers
  2. If you use some profiler you will find few dozens of call made inside that function for doing the things using library which consumes few of MILLISECONDS. but this is not really a big deal considering time we saved during the development
  3. You have to trust on the library regarding what they say. So i will suggest to stick to good ones only. And yes u r using one of the finest

Hope that helped,

Anil Namde