you have to fix the xhrobj.open("GET",str);
, the second parameter of the open method, which here is str
, is the URL you want to read your data from and it couldn't read data from anywhere, it should start with the same domain which you'r current page has, unless you have added Access-Control-Allow-Origin: *
header to your server response headers,
I just changed your exact code with a valid url and it perfectly works. check out your DEMO
BTW, I read some discussions in your comments about passing null argument in send method, when you create a XMLHttpRequest you have to send something, and when your http method is GET
you have to pass null because it is Http Get, although in some browsers you can just call send()
method without passing null as an argument but passing null would guarantee your code for all browsers.