【问题标题】:Sweet Alert with laravel带有 laravel 的甜蜜警报
【发布时间】: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');
      }

当按下“检查违规时,没有任何反应,在查看页面时,它正在加载到浏览器中但没有出现弹出窗口......

【问题讨论】:

标签: javascript php laravel sweetalert


【解决方案1】:

它不起作用,因为您使用的是 ajax 并且 Alert 正在使用 session 来显示 sweetalert 对话框

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 2017-01-04
    • 1970-01-01
    • 2023-03-20
    • 2018-07-25
    • 1970-01-01
    • 2020-11-20
    相关资源
    最近更新 更多