Monday, March 20, 2017

getting 404 not found when submitting form using ajax in laravel

    > Blockquote
    I am new with laravel ,I am having an issue when posting my data to controller in laravel while using ajax. My view contains a select box which is populated from database when a user select a value from select box i am trying to call ajax which will return details of salary of the user.The issue is it gives me 404 not found error.

Blockquote The Code for the controller file is shown below. enter code here this function is defined inside a controller public function getPostSalary() { echo "ajax called"; return 'true'; } Blockquote The Routes file is Route::post('company/salary-user', 'CompanyController@getPostSalary'); this is my ajax code from where the controller is being calleD Blockquote $(document).ready(function() { $('#employee').change(function(){ var values=$('#employee').val(); if(values== '') { $.pnotify({ title :'Message', text : 'Please Select a User.', type : 'error', delay :3000 }); return false; } var csrf = $('#csrf').val(); $.ajax({ url : '{!! URL::to("company/salary-user")!!}', type: "POST", data :{ user_id : values , _token: csrf }, cache:false, beforeSend: function(){

                          },
                        success : function(data){
                            console.log(data);
                             $('#loader').hide();
                        }            
                 });            
            }); 
    });
    </script>
> Blockquote
    what is the issue and what should be done to call my function. Thanks to ALL IN ADVANCED.



via Ashutosh Parashar

Advertisement