我正在尝试发送customer ID
来进行快速检查,以检查用户名下是否存在任何违规行为。在对任何客户ID进行硬编码时,我都将期望的结果返回到控制台中,我想在一个小的alert
框上显示以下内容:
HTML :
<strong>Customer ID:</strong>
<input class="form-control" type="text" name="custidno" id='cust' autocomplete="off" onkeypress="myFunction()" placeholder="Customer ID" value="{{ old('custidno') }}">
<input type="button" id="violationchecker" class="btn btn-info" style="background:#692563;color:white;" value="Check for Violations">
脚本:
var path = "{{ url('violationcheck') }}";
var singleValues = $( "#cust" ).val();
$("#violationchecker").click(function() {
$.get(path, { custidno : singleValues }
,function(data){
alert(checked)
});
});
控制器:
public function violationcheck(Request $request)
{
$checked = DB::table('violations')
->select('severity',DB::raw('count(*) as total'))
->where("custidno",$request->custidno)
->groupBy('severity')
->get();
return response()->json($checked);
}
答案 0 :(得分:0)
将singleValues变量放在click事件函数中。如下:
var path = "{{ url('violationcheck') }}";
$("#violationchecker").click(function() {
var singleValues = $( "#cust" ).val();
$.get(path, { custidno : singleValues }
,function(data){
alert(checked)
});
});
希望它对您有帮助。