Javascript XmlHttpRequest.responseText结果?

Javascript XmlHttpRequest.responseText结果?,javascript,xmlhttprequest,responsetext,Javascript,Xmlhttprequest,Responsetext,我是JavaScript新手。我需要在给定的URL上测试XMLHttpRequest.responseText的输出。最简单的方法是什么 var url = "http://m.google.com/"; <br> var xmlHttp = new XMLHttpRequest(); <br> xmlHttp.open('GET', url, true); <br> document.getElementById('main-content').innerH

我是JavaScript新手。我需要在给定的URL上测试
XMLHttpRequest.responseText
的输出。最简单的方法是什么

var url = "http://m.google.com/"; <br>
var xmlHttp = new XMLHttpRequest(); <br>
xmlHttp.open('GET', url, true); <br>
document.getElementById('main-content').innerHTML = xmlHttp.responseText; <br>
var url=”http://m.google.com/"; 
var xmlHttp=new XMLHttpRequest()
open('GET',url,true)
document.getElementById('main-content')。innerHTML=xmlHttp.responseText
主要内容
是一个
标签。最后一行代码将用
xmlHttp.responseText
的输出替换
标记的内容

现在,当我在我的常规浏览中打开
m.google.com
并选择“查看源代码”时,源代码的哪一部分被放置在
标记中。或者让我们留下来,我必须测试这段代码-我在哪里写这段代码


实际上,我有一个Android应用程序,它在
WebView
中显示这个HTML代码结果

使用Firebug获取Firefox并浏览XMLHttpRequest对象以查找responseText成员。

跳过您的沮丧情绪并使用它。这是一个独立的标准,几乎每个雇主都会问你是否有这方面的经验

$.get({
 url:'url.html',
 data:{},
 success:function(evt){console.log(evt);}
});
但是,如果您想选择更困难的路线:

var url = "http://m.google.com/"; 
var xmlhttp = new XMLHttpRequest(); 
xmlhttp.open("GET", url,true);

 // subscribe to this event before you send your request.
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   //alert the user that a response now exists in the responseTest property.
   alert(xmlhttp.responseText);
   // And to view in firebug
   console.log('xhr',xmlhttp)
  }
 }
 xmlhttp.send(null)

测试输出是什么意思?XMLHttpRequest.responseText.test(/sumfin/i)?请详细定义您的问题。添加了更新。请帮忙!您正在打开连接,但从未发送请求。我已经更新了我的答案,谢谢你的回复!我安装了Firebug,但在哪里可以看到XMLHttpRequest对象。我只是想澄清一下,我正在从我的应用程序访问m.google.com。我创建XMLHttpRequest对象,然后在应用程序中使用
XMLHttpRequest.responseText
。我如何看到该输出?感谢jbcurtin,我如何从java订阅该事件?如果你也给我相同的调用代码那就太好了。对不起,我对JS完全陌生。不用担心,伙计。在javascript中处理事件时(javascript不是java,这有很大的区别),您需要创建一个函数来处理它。在您的例子中,xmlhttp.onreadstatechange=function(evt){//code to handle\n}。对于其他阅读,w3schools非常棒。