I think the code is right, but I don't get any response in my second alert. When I go to the website given in the first alert, I get the text I want. Why doesn't it work?
<script type="text/javascript">
function getimages(q) {
bossimagesrequest = new XMLHttpRequest;
var requri = "http://boss.yahooapis.com/ysearch/images/v1/"+escape(q)+"?appid=yahoobosskey&filter=true&count=10";
bossimagesrequest.open("GET", requri, true);
bossimagesrequest.onreadystatechange = function() {
if (bossimagesrequest.readyState === 4) {
alert(requri);
alert(bossimagesrequest.responseText);
}
};
bossimagesrequ开发者_StackOverflow社区est.send();
}
</script>
I did replace "yahoobosskey" with my API key, so that's not the problem.
It looks like you have bumped into the same origin policy. You may have to use a relative path instead of your absolute http://boss.yahooapis.com/...
path.
Related: Empty responseText from XMLHttpRequest
You may also be interested in checking out the following Stack Overflow community wiki post:
- Ways to circumvent the same-origin policy
精彩评论