【发布时间】:2019-11-05 11:47:57
【问题描述】:
我正在尝试使用 Sweet Alert 弹出一个简单的弹出窗口,基本上我希望能够检查用户在他的记录中是否有任何以前的违规行为。我已经制作了一个控制器方法来检查它,在我看来我我正在使用 Ajax 来触发该方法.. 我正在使用 realrashid sweet alert JS 库 这是我的看法:
@include('sweetalert::alert')
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
<strong>Customer ID:</strong>
<input class="form-control" type="text" name="custidno" id='cust' required autocomplete="off" onkeypress="myFunction()" placeholder="Customer ID" >
<button onclick="CheckViolation()"class="btn-info"type="button">Check for Violation</button>
</div>
</div>
脚本
function CheckViolation()
{
var customerid= document.getElementById("cust").value;
var url = "{{ url('violationcheck') }}";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
}
};
xhttp.open("GET", url + "?" +"custidno=" + customerid, true);
xhttp.send();
}
和控制器方法:
public function violationcheck(Request $request)
{
$custidno = customer::select("id")
->where('name',$request->custidno)
->first();
$checked = DB::table('violations')
->select('severity',DB::raw('count(*) as total'))
->where("customer_id",$custidno->id)
->where("status",1)
->groupBy('severity')
->first();
if(empty($checked))
{
Alert::info('Info Message', 'No Violation found');
}else{
$msg="Violation found";
Alert::info('Info Message', 'Violation found');
}
return view('assignees.create');
}
当按下“检查违规时,没有任何反应,在查看页面时,它正在加载到浏览器中但没有出现弹出窗口......
【问题讨论】:
-
一些合理的代码格式和缩进会让你的代码更容易阅读。
-
您是否将 sweetalert .js 和 .css 包含在您的视图中? github.com/uxweb/sweet-alert#the-view
标签: javascript php laravel sweetalert