繁体   English   中英

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

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

当我在javascript函数中使用Ajax检索某个值时,而不是在页面上的任何字段(例如document.getElementbyId("").innerHTML=.....respnseText)中检索responsetext值时,希望得到警报。任何人都可以帮忙。

看一下alert()方法:

 alert(myAjaxRequest.responseText);

不会只是

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM