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').innerHTML = xmlHttp.responseText; <br>
main-content
<div>
标签。最后一行代码将用
xmlHttp.responseText
的输出替换
<div>
标签的内容。 现在,当我在常规浏览中打开
m.google.com
并选择“查看源”时,源的哪个部分放在
<div>
标签内。或者让我留下来我必须测试这段代码 - 我在哪里编写这段代码? 实际上,我有一个Android应用程序,在
WebView
中显示此HTML代码结果。     
已邀请:
轻松挫败并使用jQuery。这是一个非常规的标准,几乎每个雇主都会问你是否有经验。
$.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)
    
使用Firebug获取Firefox并浏览responseText成员的XMLHttpRequest对象。     

要回复问题请先登录注册