weixin_33749131 2018-10-09 07:57 采纳率: 0%
浏览 61

Laravel Ajax返回404

I'm trying to send data to back-end and i'm getting 404 error with this explanation in network tab:

"message": "",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",

Route

Route::middleware('verified')->group(function () {

   Route::post('/snaptoken/{id}', 'Admin\PayController@token')->name('securepaymentnow');
});

Controller

public function token(Request $request, $id) 
    {
        //Find project
        $project = Project::findOrFail($id);

        //rest of data
    }

Blade

//form and button
  <form id="payment-form" method="POST" action="{{route('securepaymentnow', $project->id)}}">
    @csrf
    <input type="hidden" name="result_type" id="result-type" value="">
    <input type="hidden" name="result_data" id="result-data" value="">
  </form>
  <button class="btn-sm bg-success pay-button" data-id="{{$project->id}}" type="submit"><i class="fas fa-fas fa-shield-alt"></i> Secure Payment</button>

//javascript

$('.pay-button').click(function (event) {
        $.ajaxSetup({
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }
        });
        event.preventDefault();
        // $(this).attr("disabled", "disabled");
        var prdfoId = $(this).data('id');
          $.ajax({
            url: '{{url("/securepaymentnow")}}/'+encodeURI(prdfoId),
            type: "POST",
            cache: false,

            success: function(data) {
              var resultType = document.getElementById('result-type');
              var resultData = document.getElementById('result-data');
            }
          });
});

Any idea?

.........................................................................................................................

  • 写回答

1条回答 默认 最新

  • from.. 2018-10-09 08:01
    关注

    if you are using url() function, you should use the {{ url('/snaptoken') }}.

    But if you want to use the "name" from the "securepaymentnow", use route() function with this example {{ route('securepaymentnow', $theId) }}.

    Both should works.

    Refer Laravel NamedRoute for details.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?