I've come to the point where I need Ajax on my page, but it's just for one small part - to see if a username typed in is in the database. As explained here Ajax can be done with JavaScript alone. What are the pros/cons of doing it this way? I'm leaning towards this because I don't want a large library and think it's unnecessarily complicated when everything else is already JavaScript alone.
Without jQuery, AJAX coding can be a bit tricky! Writing regular AJAX code can be a bit tricky, because different browsers have different syntax for AJAX implementation. This means that you will have to write extra code to test for different browsers.
Use caution and test a small area first on delicate surfaces such as fiberglass, imitation marble, plastics, and enameled appliances. Use plenty of water, rub gently and rinse well. Do not use on silver, fabrics, painted surfaces or plexiglass.
AJAX is still relevant and very popular, but how you write it may change based on what libraries or frameworks are in the project. I almost never use the "raw" JavaScript way of writing it because jQuery makes it easier and is almost always already loaded into a project I'm working on.
There's nothing wrong with using AJAX and JavaScript in your web application.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With