由网友(走)分享简介:我通过jQuery使用阿贾克斯,我试图用翻译在谷歌翻译服务。该服务似乎并没有为我工作。I am using Ajax via jQuery, and I am trying to translate using the Google Translate Service. The service does not se...
我通过jQuery使用阿贾克斯,我试图用翻译在谷歌翻译服务。该服务似乎并没有为我工作。
I am using Ajax via jQuery, and I am trying to translate using the Google Translate Service. The service does not seem to work for me.
我是什么做错了吗?我怎么会去在我的web应用程序中使用呢?
What am I doing wrong? How would I go about using this in my web application?
推荐答案
您可以做到这一点是这样的:
You can do it like this:
$.ajax({
url: 'https://ajax.googleapis.com/ajax/services/language/translate',
dataType: 'jsonp',
data: { q: 'Hello world!', // text to translate
v: '1.0',
langpair: 'en|es' }, // '|es' for auto-detect
success: function(result) {
alert(result.responseData.translatedText);
},
error: function(XMLHttpRequest, errorMsg, errorThrown) {
alert(errorMsg);
}
});
相关推荐
最新文章