Reputation: 10653
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
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
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
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
Reputation: 41822
Easy. JQuery.
Downside:
Upsides:
Upvotes: 2