|
You last visited: Today at 15:05
Advertisement
XHR vs jQuery ajax vs get vs fetch
Discussion on XHR vs jQuery ajax vs get vs fetch within the Web Development forum part of the Coders Den category.
02/28/2018, 10:21
|
#1
|
elite*gold: 0
Join Date: Apr 2011
Posts: 147
Received Thanks: 5
|
XHR vs jQuery ajax vs get vs fetch
which one should i use and why?
and what is the differents (im a beginner)
Code:
var xhr = new XMLHttpRequest();
xhr.onload = function() {alert(1)};
xhr.open("get", "http://--------.com", true);
xhr.send();
Code:
var xhr = new XMLHttpRequest();
xhr.addEventListener( "loadend", function() {alert(1)} );
xhr.open("GET", "http://--------.com", true);
xhr.send();
Code:
var request = $.ajax({
type: 'GET',
url: "http://--------.com",
async: true,
success: function() {alert(1);}
});
Code:
var request = $.get("http://--------.com").done(function() {
alert(1);
});
Code:
fetch("http://--------.com").then(function(response) {
alert(1);
});
Code:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {"done"}
}
xhr.open("GET", "http://--------.com", true);
xhr.send();
|
|
|
02/28/2018, 14:28
|
#2
|
elite*gold: 1337
Join Date: Apr 2013
Posts: 6,480
Received Thanks: 3,191
|
$.get(url) is equivalent to $.ajax({type: "GET", url: url}), so it's just a short form.
Whether you use $.get or $.ajax depends on how far you have to specify the request. With $.ajax you can pass some more options to the request.
$.ajax is the same as XHR, only made easier to use.
Fetch has some missing events in contrast to XHR, like:
- progress event
Code:
xhr.upload.onprogress = function(evt){
// Math.round((evt.loaded / evt.total) * 100) + "%"
};
xhr.upload.onload = function(){
// finished
};
- overriding content-type header of the response
...
I'd recommend using jquery's methods and if it's a simple request $.get.
|
|
|
02/28/2018, 15:42
|
#3
|
elite*gold: 0
Join Date: Apr 2011
Posts: 147
Received Thanks: 5
|
Quote:
Originally Posted by iMostLiked
$.get(url) is equivalent to $.ajax({type: "GET", url: url}), so it's just a short form.
Whether you use $.get or $.ajax depends on how far you have to specify the request. With $.ajax you can pass some more options to the request.
$.ajax is the same as XHR, only made easier to use.
Fetch has some missing events in contrast to XHR, like:
- progress event
Code:
xhr.upload.onprogress = function(evt){
// Math.round((evt.loaded / evt.total) * 100) + "%"
};
xhr.upload.onload = function(){
// finished
};
- overriding content-type header of the response
...
I'd recommend using jquery's methods and if it's a simple request $.get.
|
thanks for your help i appreciate that, now i understand abit more
i have another question, so jquery is a library, ajax is doing the samething as xhr but behind the scenes to make it easier right?
|
|
|
02/28/2018, 15:57
|
#4
|
elite*gold: 1337
Join Date: Apr 2013
Posts: 6,480
Received Thanks: 3,191
|
Quote:
Originally Posted by ahmed1234550
thanks for your help i appreciate that, now i understand abit more
i have another question, so jquery is a library, ajax is doing the samething as xhr but behind the scenes to make it easier right?
|
Yes, correct!
|
|
|
02/28/2018, 16:04
|
#5
|
elite*gold: 0
Join Date: Apr 2011
Posts: 147
Received Thanks: 5
|
Quote:
Originally Posted by iMostLiked
Yes, correct!
|
alright thanks for your help
#close
|
|
|
03/01/2018, 18:41
|
#6
|
elite*gold: 0
Join Date: May 2010
Posts: 6,853
Received Thanks: 5,106
|
|
|
|
 |
Similar Threads
|
Proffesional Front-end (Html,css,js (jquery,ajax)), Back-End (PHP) solutions
04/14/2014 - Coders Trading - 1 Replies
Hello, i offer you Professional Front-end, Back-end solutions.
I have more than 3 years of PHP/HTML/CSS experience
About 2 years of Javascript developing
MVC, OOP, Jquery, AJAX are my best friends.
I work with Codeigniter (back-end) and Foundation (Front-end) Frameworks.
I`m working with Joomla CMS too.
|
Jquery Ajax PHP HTML Java PLEASE HELP ME!
05/04/2011 - Main - 0 Replies
Hallo Com,
http://ralphwhitbeck.com/content/binary/JQuery_lo go_color_onwhite.png
Ich suche jemanden der mich in skype adden kann und mir hilft,
ich habe ein javascript (das ich hier nicht veröffentliche) und möchte da ein PHP script einbauen. Aber es geht nicht so wie ich es will
bitte helf mir jemand persöhnlich
skype ist am besten
|
Jquery/Ajax [FRAGE]
02/07/2011 - Metin2 Private Server - 23 Replies
Ich wollte mal fragen...
ich habe ne webseite und möchte im content bereich etwas anzeigen lassen
ohne die seite neu laden zu müssen
also
es gibt zum beispiel
|
All times are GMT +2. The time now is 15:05.
|
|