[英]How to add user input in a text box into the url to open a new webpage?
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. 我目前在JS方面很虚弱,所以遇到了困难。
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" 然后,我必须将用户输入传递到url中,即q =“ input from text box”
https://www.googleapis.com/language/translate/v2/detect?key=123&q= "input from text box" please help. https://www.googleapis.com/language/translate/v2/detect?key=123&q= “来自文本框的输入”请提供帮助。
What shoul i do with window.open() so that this happens? 我应该怎么用window.open()做到这一点?
<input type="text" id="lang" />
window.open('https://www.googleapis.com/language/translate/v2/detect?key=123&q='+document.getElementById('lang').value);
I would use jQuery since you will need to use JSONP : 我将使用jQuery,因为您将需要使用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. 我忽略window.open,因为响应是该请求的JSON。 You can display it anyway you want. 您可以随时显示它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.