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..
Take a look at the alert()
method:
alert(myAjaxRequest.responseText);
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)
精彩评论