简体   繁体   English

Laravel如何从控制器到刀片使用按钮

[英]Laravel How to use button from controller into blade

I'm using ajax to pass data from controller and the controller pass the response html to the ajax, this html contains a button, I want to use this button inside the blade again in jquery function, this button contains data and wants to use this data to pass it again to another controller function 我正在使用ajax从控制器传递数据,并且控制器将响应html传递给ajax,此html包含一个按钮,我想在jquery函数中再次在刀片内使用此按钮,此按钮包含数据并且要使用此按钮数据再次传递给另一个控制器功能

in controller 在控制器中

  <button class="remove_this OrderItem_action Button_root" data-id="'.$Product->rowId.'" data-price="'.$Product->price*$Product->qty.'" data-qty="'.$Product->qty.'" type="submit">Remove</button>

I want to implement this function using the passed button, like this example but it doesnt work, how can I do this 我想使用传递的按钮来实现此功能,例如本示例,但它不起作用,我该怎么做

<script>
 $(function(){ 
$('.remove_this').on("click", function () { 
 alert('just test');
   });
 });
</script>

You should pass the data like $Product->rowId to the blade with return view('index')->with($Product) . 您应该将$Product->rowId类的数据传递给带有return view('index')->with($Product)的刀片。 Then you can call your variable $Product in your blade like {{ $Product->id }} 然后,您可以像{{ $Product->id }}一样在刀片中调用变量$ Product。

In your situation: 在您的情况下:

Controller 控制者

return view('index')->with($Product)

Blade

<button class="remove_this OrderItem_action Button_root" data-id="{{ $Product->rowId }}" data-price="{{ $Product->price*$Product->qty }}" data-qty="{{ $Product->qty }}" type="submit">Remove</button>

then you can pass your jquery in your blade using the @push() method 那么您可以使用@push()方法将jquery传递到刀片中

@push('scripts')
  <script>
      $(function(){ 
          $('.remove_this').on("click", function () { 
              alert('just test');
          });
      });
  </script>
@endpush

你可以解决这个问题,只是使用这个

       $(document).on('click','.remove_this', function () { ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM