AJAX completes the URL from where it was called

Asked

Viewed 65 times

0

I’m starting to use AJAX now, so I don’t know if this is what’s going on with him. I made this code to do a CPF search in the database

$('#btn_buscar_cpf_responsavel').on('click', function(){
        var cpf = $('#aluno_responsavel_cpf').val();
        if (cpf == '') {
            alert('Informe um CPF');
        } else {
            $.ajax({
                url: '192.168.0.26/cvt-sergipetec/utils/verify_responsavel_cpf',
                type: 'POST',
                data: {'cpf' : cpf},
                dataType: 'json',
                success: function(data) {
                    if ($.isEmptyObject(data)) {
                        alert('Responsável não cadastrado');
                        $('#responsavel_novo').val(1);
                    } else {
                        $('#aluno_responsavel_nome').val(data[0].responsavel_nome);
                        var rg_uf = data[0].responsavel_rg + '/' + data[0].responsavel_rg_uf;
                        $('#aluno_responsavel_rg').val(rg_uf);
                    }
                },
                error: function() {
                    alert('Ocorreu um erro' + Error);
                }
            });
        }
    });

And I want him to send the post to this URL, but he’s completing the URL from where he was called the one I passed on the code, and here’s the following:

http://192.168. 0.26/cvt-sergipetec/pupils/192.168.0.26/cvt-sergipetec/utils/verify_responsavel_cpf

Have some way so that it doesn’t start the URL with http://192.168.0.26/cvt-sergipetec/alunos?

  • He’ll send the one you put in the option url, that is to say: url: '192.168.0.26/cvt-sergipetec/utils/verify_responsavel_cpf'

  • So he’s sending it to http://192.168. 0.26/cvt-sergipetec/students/ (where AJAX was called) + which I put in the url option: 192.168.0.26/cvt-sergipetec/utils/verify_responsavel_cpf

  • 1

    puts http:// in url since you are informing the absolute way. So: url: 'http://192.168.0.26/cvt-sergipetec/utils/verify_responsavel_cpf'

  • It worked! Thank you!

1 answer

1


Since you are informing the absolute path in the option url from Ajax, add the protocol http://:

url: 'http://192.168.0.26/cvt-sergipetec/utils/verify_responsavel_cpf'

If not Ajax will understand that this is a way from where he is being called, namely that 192.168.0.26/cvt-sergipetec/utils/verify_responsavel_cpf is a subfolder.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.