Javascript 在搜索文本框中键入日期值时如何避免ajax错误?
我有一个日期搜索功能,可以很好地一次输入完整的日期输入,例如:('10/30/2019'),但如果我输入它,例如:('10/'),它会抛出一个ajax错误(附屏幕截图) 我的bal.js文件:Javascript 在搜索文本框中键入日期值时如何避免ajax错误?,javascript,ruby-on-rails,datatables,Javascript,Ruby On Rails,Datatables,我有一个日期搜索功能,可以很好地一次输入完整的日期输入,例如:('10/30/2019'),但如果我输入它,例如:('10/'),它会抛出一个ajax错误(附屏幕截图) 我的bal.js文件: $(document).ready(function() { $("table[role='bal_datatable']").each(function() { var table = $(this).DataTable({ "order": [ [7, "des
$(document).ready(function() {
$("table[role='bal_datatable']").each(function() {
var table = $(this).DataTable({
"order": [
[7, "desc"]
],
columnDefs: [{
"searchable": false,
"targets": 9
},
{
"searchable": false,
"targets": 10
},
{
"orderable": false,
"targets": 9
},
{
"orderable": false,
"targets": 10
},
{
"className": "abc",
"targets": [5]
}
],
autoWidth: false,
pageLength: 50,
processing: true,
serverSide: true,
ajax: $(this).data('url')
});
// Setup - add a text input to each footer cell
$('#balances tfoot th').each(function(i) {
var title = $(this).text();
$(this).html('<input type="text" placeholder="' + title + '" />');
$('input', this).on('keyup change', function() {
if (table.column(i).search() !== this.value) {
table
.column(i)
.search(this.value)
.draw();
}
});
});
});
})
$(文档).ready(函数(){
$(“表[role='bal_datatable'])。每个(函数(){
var table=$(this).DataTable({
“命令”:[
[7,“描述”]
],
columnDefs:[{
“可搜索”:错误,
“目标”:9
},
{
“可搜索”:错误,
“目标”:10
},
{
“可订购”:错误,
“目标”:9
},
{
“可订购”:错误,
“目标”:10
},
{
“类名”:“abc”,
“目标”:[5]
}
],
自动宽度:false,
页长:50,
处理:对,
服务器端:是的,
ajax:$(this.data('url'))
});
//设置-向每个页脚单元格添加文本输入
$(“#平衡tfoot th”)。每个(功能(i){
var title=$(this.text();
$(this.html(“”);
$('input',this).on('keyup change',function()){
if(table.column(i).search()!==此.value){
桌子
.第(i)栏
.search(此.value)
.draw();
}
});
});
});
})
My bal_datatable.rb:
def bal_method1(balances)
if(@tabular.search7 > '00/00/0000' )
balances.where("balances.updated_at > (:search) and balances.updated_at < (date (:search) + interval '1 day')", {search: "#{@tabular.search7}"})
else
balances.where("1 = 1")
end
end
def bal_方法1(余额)
如果(@tabular.search7>'00/00/0000')
余额。其中(“balances.updated_at>(:search)和balances.updated_at<(date(:search)+interval'1 day'),{search:{@tabular.search7}})
其他的
余额。其中(“1=1”)
结束
结束
请帮忙
if( this.value.match(/(\d{2}\/\d{2}\/\d{4})/))
{ table.column(i).search( this.value ).draw(); }
else if( this.value == '')
{ table.column(i).search( this.value ).draw(); }