如何使用通过Ajax谷歌翻译使用jQuery? [英] How can I use Google Translate via Ajax using jQuery?

查看:470
本文介绍了如何使用通过Ajax谷歌翻译使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过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);
    }  
});

这篇关于如何使用通过Ajax谷歌翻译使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆