weixin_33725272 2018-12-03 07:44 采纳率: 0%
浏览 37

如何在Laravel中创建Ajax

i want to show my data when i click button with ajax.

here ajax that i try.

  $(document).ready(function(){
    $(document).on('click', '#detailptr', function(){
       var idpartner = $(this).data("vid");
       $('#detailptr').html("Loading...").prop("disabled", true);
       $.ajax({
          url:"{{URL::route('front.partnereemployee')}}"+idpartner,
          method:"GET",
          data:{idpartner:idpartner},
          dataType:"text",
          success:function(data)
          {
             if(data != '')
             {
                //$('#remove_row').remove();
          $("#remove_row").html(data);
             }
             else
             {
                //$('#detailptr').html("Sudah Semuanya");
             }
          }
       });
    });
  });

my html

<a type="button" data-toggle="collapse" data-target="{{ $key }}" data-vid="{{ $companys->CompanyID }}" id="detailptr">{{ $companys->CompanyName }}</a>

and this is my route

Route::get('/partnere/{id}', 'Front\Home\FrontController@employeeajax')->name('front.partnereemployee');

when i try to run, it always show me

Missing required parameters for [Route: front.partnereemployee] [URI: partnere/{id}]

  • 写回答

2条回答 默认 最新

  • weixin_33705053 2018-12-03 08:06
    关注

    Jquery has a shorthand for ajax calls which is more convenient
    $.get
    $.post

    for your case it would be

    $.get('{{ route('front.partnereemployee') }}' + idpartner, {idpartner: idpartner}).done(function () {
            alert("second success");
        })
        .fail(function () {
            alert("error");
        }).always(function () {
            alert("finished");
        });
    
    评论

报告相同问题?