Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda