开发者

XMLHttpRequest and Bing translator

开发者 https://www.devze.com 2023-02-15 05:39 出处:网络
If the following code I don\'t get status 200 and responseText. But this URL works: http://api.microsofttranslator.com/V2/Http.svc/GetLanguagesForTranslate?appId=F1B50AB0743B541AA8C07089042D7B57E9B28D

If the following code I don't get status 200 and responseText. But this URL works: http://api.microsofttranslator.com/V2/Http.svc/GetLanguagesForTranslate?appId=F1B50AB0743B541AA8C07089042D7B57E9B28D25. Also in Wireshark I see that I get status 200 and data which is expected. What is the problem with my Javascript code?

function btnclick()
{
    var http = new XMLHttpRequest();
    var str = "";
    http.open('GET', 'http://api.microsofttranslator.com/V2/开发者_JAVA技巧Http.svc/GetLanguagesForTranslate?appId=F1B50AB0743B541AA8C07089042D7B57E9B28D25',
    true);
    http.onreadystatechange = function (evt)
    {
        if (http.readyState == 4 && http.status == 200)
        {
            alert(http.responseText);
        }
    }
    http.send(null);
}


You are trying to make a cross domain XHR. That violates same origin policy.

You could build a server side proxy, and request that with XHR.


If you are doing AJAX, you might want to use the AJAX version to overcome the cross domain issue. http://msdn.microsoft.com/en-us/library/ff512404.aspx

0

精彩评论

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