开发者

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

开发者 https://www.devze.com 2023-04-12 18:39 出处:网络
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(\"\")开发者_开发百科.innerH

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号