【问题标题】:Laravel How to use button from controller into bladeLaravel 如何使用控制器中的按钮进入刀片
【发布时间】:2018-07-24 04:22:41
【问题描述】:

我正在使用ajax从控制器传递数据,控制器将响应html传递给ajax,这个html包含一个按钮,我想在jquery函数中再次使用刀片内部的这个按钮,这个按钮包含数据并且想要使用此数据再次将其传递给另一个控制器函数

在控制器中

  <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>

我想使用传递的按钮来实现这个功能,就像这个例子但是它不起作用,我该怎么做

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

【问题讨论】:

    标签: javascript php jquery laravel


    【解决方案1】:

    你可以用这个解决这个问题

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

    【讨论】:

      【解决方案2】:

      您应该将$Product-&gt;rowId 之类的数据传递给带有return view('index')-&gt;with($Product) 的刀片。然后你可以在你的刀片中调用你的变量 $Product 像{{ $Product-&gt;id }}

      在你的情况下:

      控制器

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

      刀片

      <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>
      

      然后你可以使用 @push() 方法在你的刀片中传递你的 jquery

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

      【讨论】:

      • 我用的是ajax,你说的不能用ajax,这会刷新页面!!!!!!!!!
      • 检查这个:pass-data-from-ajax-to-controller-in-laravel。也许会解决你的问题。
      • 你理解我的意思吗?我没有返回数据的问题!返回此数据后的问题是使用此数据中的一个按钮来使用它来实现某些东西
      • 那你需要更清楚.. I want to implement this function using the passed button, like this example but it doesn't work, how can I do this 什么不完全.. 你有控制台错误日志什么的吗?
      猜你喜欢
      • 1970-01-01
      • 2019-02-06
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      • 2018-03-24
      • 1970-01-01
      • 2016-07-13
      相关资源
      最近更新 更多