Shaoz
Shaoz

Reputation: 10653

Traditional Ajax or Jquery Ajax, which one is better?

This is just a general question. Which is better, traditional ajax or the jquery ajax? Because when I use the jquery ajax, it seems to do funky weird stuffs in IE. And it supposed to be a cross-browser library... So I'm a bit confused as to which one to use. Again I'm asking this because of the serial-killer IE...

The funky weird stuff, i.e. sometimes it stops sending information to the server after just a few requests, even when I put 'cache: false'.

Upvotes: 0

Views: 195

Answers (4)

Daniel Vassallo
Daniel Vassallo

Reputation: 344311

jQuery $.ajax() should work fine in IE. It uses XMLHttpRequest just like what you'd use if you were to do it yourself. But jQuery's method has grown little hairs and stuff on it to make it work consistently between different browsers, as much as possible.

Give a look to jQuery's ajax source code. One reason it's 593 sloc, and not just 4, is to fix and wrap all the inconsistencies between the different browsers. The comments will reveal many of these issues.

Upvotes: 2

bobince
bobince

Reputation: 536379

There's not a meaningful difference. jQuery's ajax() is naturally built on XMLHttpRequest and they should behave the same. I think some other scripting error is causing the “funky weird stuffs”.

Note if you want to do cross-browser XMLHttpRequest without a large JS library, it's actually pretty simple these days. All you need is the fixup for IE6:

if (!window.XMLHttpRequest && 'ActiveXObject' in window) {
    window.XMLHttpRequest= function() {
        return new ActiveXObject('MSXML2.XMLHttp');
    }
}

and then you can use the standard new XMLHttpRequest interface anywhere. There is no longer any need to deploy the overrideMimeType hack (which was for ancient Mozilla milestone builds), and there never was any need to try multiple ActiveXObject progids.

Upvotes: 5

Roman
Roman

Reputation: 10403

You'll obviously have to spend time to learn the jQuery framework but the upshot is that jQuery is one of the most used JS frameworks. So your investment in time will pay off as you'll find jQuery can do other things than just Ajax communication.

Also the way that jQuery allows traversing the DOM tree is supreme which makes developing things in jQuery very simple.

Upvotes: 2

sje397
sje397

Reputation: 41822

Easy. JQuery.

Downside:

  1. Extra script load

Upsides:

  1. Standardizes the API across all major browsers
  2. Consistent < 2 min wait for an answer here on SO for any question you have :)
  3. Much enhanced functionality

Upvotes: 2

Related Questions