This url with right api-key https://www.googleapis.com/language/translate/v2?key=XXXXXXX&target=ru&source=en&q=hello contains:
{
"data": {
"translations": [
{
"translatedText": "привет"
}
]
}
}
URL works 100%, I tested it in browser.
You can read about it here – http://code.google.com/apis/language/translate/v2/getting_started.html
I want to get it with JQuery and insert in specific div:
var url = 'https://www.googleapis.com/language/translate/v2?key=XXXXXXX&target=ru&source=en&q=hello'
$.get(url, function(response) {
$('div#translation').html(response.data.translations[0].translatedText);
});
It is not working. data is empty. I cannot figure out where the problem is. It should work.
I tried to insert text from this url in local file and use it in url, then it works!
What is wrong here?
I believe your problem is the the Same-Origin-Policy mentioned by ZeissS. Have a look at http://code.google.com/apis/language/translate/v1/using_rest_translate.html and read the section entitled “Using the callback argument”. This should avoid the same-origin-policy problem.
More information on JSONP and why it’s sometimes needed can be found here: http://en.wikipedia.org/wiki/JSONP