【发布时间】:2021-01-23 08:34:10
【问题描述】:
我想用 Javascript 构建一个简单的网站,加载时会用中文打印“你好”。
为此,我尝试使用谷歌翻译调用,如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- bootstrap.min.css + some js related files -->
<body onload="myFunction()">
</body>
</head>
<script>
function myFunction()
{
//alert("hello");
var ourRequest = new XMLHttpRequest();
var API;
API = 'https://translate.google.co.in/?sl=auto&tl=zh-CN&text=hello&op=translate';
//alert(API);
ourRequest.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
alert(ourRequest.responseText);
}
};
ourRequest.open('GET', API,false);
ourRequest.send();
}
</script>
</html>
当我尝试运行它时,我收到以下错误:
try.html:43 GET https://translate.google.co.in/?sl=auto&tl=zh-CN&text=hello&op=translate403
似乎谷歌服务器拒绝了我的电话。 有人可以帮我解决这个问题吗?
问候
【问题讨论】:
标签: javascript http-status-code-403