Mahesh Chandran
Mahesh Chandran

Reputation: 1

ajax is not working in laravel

$(document).ready(function () {

    $('#designation').change(function () {
        var opt=this.value;
       // var login_url = '{{ url("ajax_crud") }}';
        alert(opt);
        $.ajax({
           //alert(opt);

           type: "post",
           url:'ajax_type' ,
           data: {option:opt},
           success: function(data){
               alert('hiii');
               //$("#div_dprtmnt").html(data);
               //document.getElementById("department").innerHTML=data;
           }
        });
    });

    });

this is my view page.jquery is working.but inside the ajax alert is not working.how to use $.ajax in laravel.please help me

Upvotes: 0

Views: 54

Answers (1)

Luke
Luke

Reputation: 1033

I think this is an issue with your CSRF token. Ensure you are attaching a token on each request to protect from forgery. You can do all this like this in ajax like this:

(document).ready(function () {
    $('#designation').change(function () {
        var opt = this.value;
        $.ajax({
           _token: "{{ csrf_field() }}",
           type: "post",
           url: "ajax_type",
           data: {
               option: opt
           },
           success: function(data){
               alert('hiii');
           }
        });
    });
});

Upvotes: 1

Related Questions