Kullu
Kullu

Reputation: 101

How to get the result of Ajax call in an alert box

when i am using the ajax within the javascript function to retrieve some value , instead of retrieving the responsetext value in any of the field(eg:document.getElementbyId("").innerHTML=.....respnseText) on the page, want to get it as an alert.Can anyone Please help..

Upvotes: 0

Views: 601

Answers (2)

Cliff
Cliff

Reputation: 1701

wouldn't it just be

alert(responseText);

Since the obvious answer is not working, try this (jquery):

$.get('foo.html', function(responseText) {
  alert(responseText);
});

if not using jquery, and just using a raw xmlhttp object, you could try this:

xmlhttp.open("GET", "foo.html", true);
xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) {
        alert(xmlhttp.responseText)
    }
}
xmlhttp.send(null)

Upvotes: 1

Matthew
Matthew

Reputation: 13332

Take a look at the alert() method:

 alert(myAjaxRequest.responseText);

Upvotes: 4

Related Questions