【问题标题】:How to pass the input type hidden values from view to the controller in laravel5如何将输入类型隐藏值从视图传递到 laravel 5 中的控制器
【发布时间】:2016-07-25 06:36:28
【问题描述】:

我的视图中有一个数据,例如

<input name="start" type="hidden" value="1" />
<input name="end" type="hidden" value="2" />

当我的页面加载时,我需要将此值传递给控制器​​。

我应该如何将它传递给控制器​​。

有没有办法使用 jQuery 发送这些值!!!...

谁来帮帮我..

【问题讨论】:

    标签: php jquery laravel-5


    【解决方案1】:

    你为什么不试试ajax

    <input name="start" class="start" type="hidden" value="some_value1" />
    <input name="end" class="end" type="hidden" value="some_value2" />
    
    var postData = {
        "param1" : some_value1,
        "param2" : some_value2
    };
    
    console.log(postData);
    
    $.ajax({
        type: "POST",
        url: "test.php",
        data: postData, 
        success: function(){
            alert(param1 + ' ' + param2);
            window.open("test.php"); 
        }
    });  
    

    test.php 是你的控制器...

    【讨论】:

    • 太棒了...我的荣幸:)
    【解决方案2】:

    试试这个

    <input name="start" class="start" type="hidden" value="1" />
    <input name="end" class="end" type="hidden" value="2" />
    
    <script type="text/javascript">
       $(function() {
        pass_value();  
       });
    
    
    function pass_value(){
       var start = $(".start").val();
       var end = $(".end").val();
       $.post('{your_url}', {start:start, end:end},function(data){
         console.log(data);
      })
    }
    
    </script>
    

    【讨论】:

      猜你喜欢
      • 2017-01-17
      • 1970-01-01
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      相关资源
      最近更新 更多