mardi 29 septembre 2015

ajax request throwing 405 method not found error (Laravel 5)

I am making an ajax call from a form to send the checkbox data to a controller. Here is the relevant html code:

 <form method="POST" action="http://ift.tt/1MCSkLV" accept-charset="UTF-8" class="del_form" id="del_form" name="del_form"><input name="_token" type="hidden" value="igr6iMt1WfeZunyG8wpyy1tNK1efgiclyOvZ1hkF">
  <input id="submit" type="submit" name="submit" value="Delete Checked Records" onclick="return submitDelForm();">
   <div class="table-responsive shadow-edge-nofill">

    <table class="table table-striped">
                    <tbody>
                    <tr>
            <td><input id="badURL0" class="bad_url_checkbox" name="bad_url_checkbox" type="checkbox" value="2"></td>

    etc....etc.....etc....

    </form>

Here is the relevant javascript code:

  <script type="text/javascript">
    function submitDelForm(){
        $('div#loadmoreajaxloader').show();
        var form = document.del_form;
        var dataString = $(form).serialize();
        $.ajaxSetup({
            headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
        });
        $.ajax({
            type: 'POST',
            URL: '/delbadurl',
            contentType: "application/json; charset=utf-8",
            data: {'serial_data' : dataString},
            success: function(data){
                $('div#loadmoreajaxloader').hide();
            }
        });
    }
</script>

Here is relevant routing:

  Route::post('delbadurl','Admin\DashboardController@delBadURL' );

I can confirm that CSRF token is being appended to the dataString. The form data is being appended to the dataString as well. However, jquery throws 405 error.

I am using many other similar ajax functions to fetch and send the data. Everything works perfectly except this particular function. Some pointers will be greatly appreciated as I am coming empty handed.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1KP92F0
via IFTTT

Aucun commentaire:

Enregistrer un commentaire