开发者

No Text appears

My code:

    <script type="text/javascript">
var req = new XMLHttpRequest();
req.open("GET","http://surfkid.redio.de/link.php");
req.send(null);
document.write(req.responseText);
</script>

{
  "name": "My First Ext开发者_运维技巧ension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "browser_action": {
   "default_icon": "android.jpg",
   "popup": "link.html"
  },
  "permissions": [
    "http://surfkid.redio.de/"
  ]
}

When i press the icon no text appears. Do anybody knows why?


I think it's because you're not using the onreadystatechange-event. Because the connection is asynchronous the response is null just after sending it.

You could do it like this:

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://surfkid.redio.de/link.php", true);
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    document.write(xhr.responseText);
  }
}
xhr.send();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜