How to transform AJAX with JQuery into pure JavaScript? [duplicate]

5

How can I make the following Javascript pure AJAX without using JQuery?

$.ajax({
  url: "http://habbxo.esy.es/test.html",
  success: function b64EncodeUnicode(entry) {
    nome = entry.split("uniqueId\":\"")[1]["split"]("\"")[0];
  }
});


        setTimeout(function(){alert(nome)},1000);
    
asked by anonymous 19.05.2016 / 02:32

1 answer

2

native version:

var xmlhttp;
var nome;

if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
} else {
    // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
       if(xmlhttp.status == 200){
           nome = xmlhttp.responseText.split("uniqueId\":\"")[1]["split"]("\"")[0];
       }
       else if(xmlhttp.status == 400) {
          alert('There was an error 400')
       }
       else {
           alert('something else other than 200 was returned')
       }
    }
};

xmlhttp.open("GET", "http://habbxo.esy.es/test.html", true);
xmlhttp.send();

setTimeout(function(){alert(nome)},1000);

Response removed from here

    
19.05.2016 / 12:33