您好,我想从一个输入字段中读取一个文本值,然后在JQUERY函数中使用它从数据库中获取数据。我想要像这样填充源: /search/batch_name_by_barnID/1,但输出类似于: /batch_name_by_barnID?term=1
如何设置此部分:源:"/search/batch_name_by_barnID/"+$('#barn_id').text(),以获取类似/search/batch_name_by_barnID/{number}的输出,而不是/search/batch_name_by_barnID?term=1
我的HTML是:
<input type="text" class="form-control search_occupied_barn_name" placeholder="Type here ..." name="barn_name">
<span class="help-block search_occupied_barn_name_empty" style="display: none;">No Results Found ...</span>
<input type="text" class="search_barn_id" name="barn_id" id="barn_id">
<label>باتش</label><br>
<input type="text" class="form-control search_batch_name_barn" placeholder="Type here ..." name="BatchName">
<span class="help-block search_batch_name_barn_empty" style="display: none;">No Results Found ...</span>
<input type="text" class="search_batch_id" name="batch_id" id="batch_id">我的JQUERY是:
$( ".search_batch_name_barn" ).autocomplete({
source: "/search/batch_name_by_barnID/"+$('#barn_id').text(),
minLength: 1,
response: function(event, ui) {
if (ui.content.length === 0) {
$(this).parent().addClass('has-error');
$(this).next().removeClass('glyphicon-ok').addClass('glyphicon-remove');
$(".search_batch_name_barn_empty").show();
$('.form_submit').hide();
} else {
$(".search_batch_name_barn_empty").hide();
$('.form_submit').show();
}
},
select: function(event, ui) {
$('.search_batch_id').val(ui.item.id);
$('.search_batch_name_barn').val(ui.item.value);
}
});发布于 2020-08-30 04:25:02
我找出了问题所在:我添加了一个按钮,然后使用搜索方法代码default.js从该按钮触发了"search_batch_name_barn“的自动完成
$("#getBatch").click(function () {
alert("test");
$(".search_batch_name_barn").show();
$(".search_batch_name_barn").autocomplete('search');
});HTML
<input type="text" class="form-control search_occupied_barn_name" placeholder="Type here ..." name="barn_name">
<span class="help-block search_occupied_barn_name_empty" style="display: none;">No Results Found ...</span>
<input type="hidden" class="search_barn_id" name="barn_id" id="barn_idorg">
<button type="button" class="btn btn-primary" name ="getBatch" id="getBatch">Get Batch</button>
<label>باتش</label><br>
<input type="text" class="form-control search_batch_name_barn" placeholder="Type here ..." name="BatchName">
<span class="help-block search_batch_name_barn_empty" style="display: none;">No Results Found ...</span>
<input type="hidden" class="search_batch_id" name="batch_id" id="batch_id">https://stackoverflow.com/questions/63637972
复制相似问题