如何在警告框中获取Ajax调用的结果

时间:2011-10-14 05:02:27

标签: javascript ajax

当我在javascript函数中使用ajax来检索某个值时,而不是在任何字段中检索responsetext值(例如:页面上的document.getElementbyId("").innerHTML=.....respnseText)),想要将其作为alert.Can任何人请帮助..

2 个答案:

答案 0 :(得分:4)

查看alert()方法:

 alert(myAjaxRequest.responseText);

答案 1 :(得分:1)

不会只是

alert(responseText);

由于明显的答案不起作用,试试这个(jquery):

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

如果不使用jquery,只使用原始的xmlhttp对象,你可以试试这个:

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