That's the only thing necessary for cross-browser support unless you need to support really old IEs (which apparently use a different ActiveXObject).
However, using e.g. jQuery provides a bunch of additional advantages:
- Single function call, no unnecessary variables cluttering your scope.
- Automated serialization of objects into GET/POST arguments. Why do that manually (you need to encode the values properly!) when you can simply pass an object?
- Automated parsing of the response, e.g. in case of JSON you get an object and not just a string you need to parse manually.
- Nice callbacks for common events (success/failure/finished)
- Pluggable architecture to support e.g. XDomainRequest for CORS in IE.
Since you mention that you cannot use jQuery because your app will be embedded in another site that might conflict with it: You can avoid this by including jQuery and then using $.noConflict(true)
to restore both the old $
and jQuery
variables. To use it in your code you then write it like this:
(function($) {
})(jQuery.noConflict(true));