[英]Value of form input not changing on readyState using Bootstrap Tags Input and AJAX
I have the following HTML form: 我有以下HTML表单:
<form method="post" action="./results.php">
<input type="submit" name="submitbtn" id="submitButton" class="btn btn-default btn-responsive" role="button">
<input name="q" id="query" value="" data-role="tagsinput"/>
</form>
After loading the page using AJAX, I want to populate the value field with the http.responseText
. 使用AJAX加载页面后,我想用
http.responseText
填充value字段。 I'm trying doing it this way: 我正在尝试这样做:
function AjaxFunction()
{
url = 'fbserver.php';
http.open("GET",url, true);
http.onreadystatechange = function()
{
if (http.readyState == 4)
{
$(".se-pre-con").fadeOut("slow");
var query = http.responseText; // The user's interests as a string
document.getElementById("query").value = query;
/* Tried refreshing the input here like suggested in the linked question ($('input').tagsinput();) */
}
}
http.send(null);
}
However, it's not working, leaving the form input empty and the value attribute unchanged. 但是,它不起作用,将表单输入保留为空,并且value属性保持不变。 I tried
document.getElementById("query").name = query;
我尝试了
document.getElementById("query").name = query;
and the name
attribute changes normally. 并且
name
属性正常更改。
I guess it has something to do with the tagsinput plugin as mentioned here , but I was unable to fix this problem based on the answers. 我猜这与这里提到的tagsinput插件有关,但是我无法根据答案解决此问题。 Any help would be appreciated!
任何帮助,将不胜感激! ;)
;)
You should use the api of the plugin rather putting the text values directly. 您应该使用插件的api,而不要直接输入文本值。
I am using jQuery (and I think the plugin also has a dependency on it, so you can use this approach also). 我正在使用jQuery(我认为插件也对此具有依赖性,因此您也可以使用此方法)。 So inyour ajax call, you can:
因此,在您的ajax调用中,您可以:
$('#query').tagsinput('add', http.responseText);
You can view the other methods here: https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/ 您可以在此处查看其他方法: https : //bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.