AJAX, Which is better?

Hi guys,

PROS and CONS of these two below,

  1. AJAX (JavaScript no framework)
  2. AJAX (jQuery)

Thanks in advance.

AFAIK jQuery AJAX is AJAX, just that it reduces the amount of code you need to write.
But that’s only because the code is already written and part of the jQuery library.

IMHO if you need jQuery for other things then you might as well use it for AJAX too, but if you’re loading the entire library for only AJAX, then it might be better to write your own AJAX code and use that to save on the bandwidth.

Unless you are going to use other parts of the jQuery framework then using plain JavaScript for your ajax call will result in the page needing to load far less code.

Also while jQuery supports two of the ways to use ajax - httprequest and jsonp - it does not support other types of ajax call such as the two line plain JavaScript call to request a dummy image that can be used when you don’t need a response from the server ( such as for a heartbeat script that tracks approximately when the person leaves your page).

The cross browser issues that jQuery 1 handles with regard to ajax calls relate to the now long dead IE 4 through 6 browsers so you can make your plain JavaScript version shorter by omitting the code for those browsers (or if you decide to use jQuery then use version 2 instead of version 1).

AJAX is one reason I would consider using the jQuery library.
The syntax makes it so easy to work with, that it’s more or less foolproof.
If your worried about size, you can create a custom build, just including the AJAX functionality.

Interesting. Could you give me an example of what that might look like?

Thanks for the input guys.

For an example of sending information to the server from JavaScript using a dummy image see http://javascriptexample.net/ajax08.php

For a complete heartbeat script using a dummy image with JavaScript, PHP and mySQL see http://javascriptexample.net/ajax09.php

Ok, thanks.