Rahul Rahul - 4 months ago 19
Ajax Question

how do I get the reponse text from ajax code

I have one url like "http://172.26.76.83/service/service.php?str".when i run this url i am getting "Hi welcome".how to write code in AJAX to get "Hi welcome"

Answer

You should've searched it a bit more. In this Link you have the easy GET method, that will look like this:

function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
     document.getElementById("demo").innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET", "http://172.26.76.83/service/service.php?str", true);
  xhttp.send();
}
Comments