Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda