laravel甜蜜警报

我正在尝试使用Sweet Alert弹出一个简单的窗口,基本上,我希望能够检查用户的记录中是否有以前的违规行为。我制作了一个控制器方法来检查该行为并在我看来正在使用Ajax触发该方法。 我正在使用realrashid甜蜜警报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');
      }

当按下“检查违规情况时,什么也没有发生,在查看页面时,它已被加载到浏览器中,但没有出现弹出窗口...

jjydjy 回答:laravel甜蜜警报

它将无法正常工作,因为您使用的是ajax,而Alert使用的是会话以显示Sweetalert对话框

本文链接:https://www.f2er.com/3159914.html

大家都在问