How bad is it to do Ajax without jQuery? [closed] How bad is it to do Ajax without jQuery? [closed] ajax ajax

How bad is it to do Ajax without jQuery? [closed]


If you don't need to support older version of IE, like IE6, then it's quite simple, you don't need any factory function, just a plain:

var http = new XMLHttpRequest();

For all browsers. Plus, in recent browsers (I believe also in IE8), you can simplify more using onload events instead of onreadystate:

var http = new XMLHttpRequest();http.open("GET", "somepage.html", true);http.onload = function () {    alert("Request complete: " + http.responseText);}http.send();

That is quite similar to the success handler of jQuery.

For further details, see: Using XMLHttpRequest

However, jQuery now has the ajax calls threat as promises, that makes some scenario (like waiting for multiple ajax calls to finish before run some code) much easier to develop.


It's not that bad... just not as small:Small Ajax JavaScript libraryas explained there, you could also just get one of those small libraries that handle ajax alone tho.

Edit:As MCL pointed out below in his comment, there is also this snippet: https://gist.github.com/mythz/1334560

It seems to implement the jQuery syntax but only for ajax calls, if you're used to it, this might be a better choice!


It's not bad at all, jQuery just provides a shortcut to do it, while writing it all manually gets a little bigger. That's pretty much it.

If you just want an "ajax helper", try using this snippet from quirksmode.: http://www.quirksmode.org/js/xmlhttp.html