0

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

3
  • Change this url:"{{URL::route('front.partnereemployee')}}"+idpartner, to url:"{{URL::route('front.partnereemployee', "idpartner")}}" Commented Dec 3, 2018 at 7:52
  • This should solve your problem. You have to pass a placeholder for the required route param and then later replace it your real param in javascript. Commented Dec 3, 2018 at 9:14
  • Try replacing url:"{{URL::route('front.partnereemployee')}}"+idpartner, with Commented Dec 3, 2018 at 13:27

2 Answers 2

0

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");
    });
Sign up to request clarification or add additional context in comments.

Comments

0

This is ther simple way for make get request in laravel Ajax.

$.ajax({ 
    type:"GET",
    url : 'your-url',
    data: {key:data},
    dataType: 'json',
    success: function(data){
                if (data.status = true) {
                document.getElementById("alert-message").innerHTML = data.message;

                console.log(data);
               } else {
                  alert('failed');
               }
            },
            error: function(data){
                alert("ajax failed");
            })
})

and if you want to pass CSRF token

<meta name="csrf-token" content="{{ csrf_token() }}">  

add this line in your header so that you can pass token in Jquery using below code,

$.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        e.preventDefault(e);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.