Reputation: 1104
Please help me with this . My problem is that - I am trying to build a language recognization tool for my blog . I am currently weak in js so finding difficulties.
All i have to do is put a text box and ask user to input the language to detect . Then I have to pass the user input into the url , ie q="input from text box"
https://www.googleapis.com/language/translate/v2/detect?key=123&q="input from text box" please help.
What shoul i do with window.open() so that this happens?
Upvotes: 2
Views: 2467
Reputation: 82654
I would use jQuery since you will need to use JSONP:
<div id="results"> </div>
....
$.ajax({
type: 'GET',
dataType: 'json',
url: 'https://www.googleapis.com/language/translate/v2/detect?key=123&q=' + $('inputId').val() + '&callback=?',
success: function (data) {
$.each(response.data.detections, function() {
$('#results').text(JSON.stringify($(this)[0].language));
})
}
});
I'm ignoring the window.open because the response is JSON from that request. You can display it anyway you want.
Upvotes: 2
Reputation: 7032
<input type="text" id="lang" />
window.open('https://www.googleapis.com/language/translate/v2/detect?key=123&q='+document.getElementById('lang').value);
Upvotes: 4