Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
getting 404 not found when submitting form using ajax in laravel

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.

The Code for the controller file is shown below.

    this function is defined inside a controller

    public function getPostSalary()
        {
            echo "ajax called";
            return 'true';
        }

The Routes file is

Route::post('company/salary-user', 'CompanyController@getPostSalary');

this is my ajax code from where the controller is being calleD

<script>
    $(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>

Can someone help me to figure out what is the issue and what should be done to call my function.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Single quotes is for string so your url is not generating as you expecting. Use like this

  url : "{!! URL::to('company/salary-user')!!}",
about 4 years ago · Santiago Trujillo Report

0

replace this line:

{!! URL::to("company/salary-user")!!}

by :

{{ url('/company/salary-user') }}

or

{{ route('/company/salary-user') }}
about 4 years ago · Santiago Trujillo Report

0

You can use direct url like

 $.ajax({
            url:'company/salary-user',
            type: "POST",
            data: { user_id: values, _token: csrf },
            cache: false,
            beforeSend: function () {

            },
            success: function (data) {
                console.log(data);
                $('#loader').hide();
            }
        });
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!