Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 652
Celeritas Avatar asked Feb 07 '13 09:02

Celeritas


People also ask

Is jQuery necessary for AJAX?

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.

What should you not use AJAX on?

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.

Is jQuery AJAX still used?

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.

Is using AJAX bad?

There's nothing wrong with using AJAX and JavaScript in your web application.


1 Answers

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.

like image 153
ZER0 Avatar answered Nov 13 '22 03:11

ZER0