【问题标题】:How to send parameter file_path to controller (laravel 5)?如何将参数 file_path 发送到控制器(laravel 5)?
【发布时间】:2016-04-03 02:50:27
【问题描述】:

我的代码是这样的:

function showAjaxPdf(file_path)
        {
            var file_path = "test/test_one.pdf".replace(/\\/g,"/");
            alert(file_path);
            $.ajax({
                url: "news/test/" + file_path,
                success: function(response)
                {
                    alert(response);
                }
            });
        }

我在控制器中的功能测试是这样的:

public function getTest($file_path)
    {
        die($file_path);      
    }

回复结果:test

应该的结果回复:test/test_one.pdf

如何获得回复结果:test/test_one.pdf

谢谢

【问题讨论】:

    标签: javascript jquery ajax laravel laravel-5


    【解决方案1】:

    假设您的路由工作正常,请将 file_path 添加到 ajax 数据中:

    JS:

    $.ajax({
    method: 'POST',
    url: "news/test",
    data: {file_path: file_path},
    success: function(response)
    {
    alert(response);
    }
    });
    

    http://api.jquery.com/jquery.ajax/

    PHP:

    $file_path = $request->file_path;
    

    https://laravel.com/docs/5.2/requests

    【讨论】:

      猜你喜欢
      • 2021-05-17
      • 1970-01-01
      • 2016-03-22
      • 2016-05-06
      • 1970-01-01
      • 2017-03-11
      • 2015-06-25
      • 2015-04-02
      • 1970-01-01
      相关资源
      最近更新 更多