Returns no error from an AJAX function

Asked

Viewed 203 times

0

Returns a alert empty when I use this code (I picked it up on the internet):

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
$(document).ready(function() 
{   
$(".busca").keyup(function() 
{
    var busca = jQuery(".busca").val();
    if(busca.length >= 1) 
    {

        jQuery.ajax(
        {
            type: "POST",
            url: "resultado.php",
            dataType: "html",
            data: "busca=" + busca,

            success: function(response)
            {
                jQuery("#retorno").html(response);
            },
            error: function(request, status, erro)
            {
                alert("Problema ocorrido: " + status + "\nDescição: " + erro);
                alert("Informações da requisição: \n" + request.getAllResponseHeaders());
            }
        });
    }
});
});
</script>

inserir a descrição da imagem aqui

  • Good morning, The error may be happening because of the return type, if it is not returning a partial in HTML... for this the method in your code also needs to be returning HTML , if your code is returning a JSON, it would have to be dataType: "JSON" ... and so on...?

1 answer

0

I made several simulated using the very code you posted (with a small change instead of displaying a Alert, the message would be displayed on itself div #return), and the only situation that occurred was when I terminated the file directly by protocol file:

inserir a descrição da imagem aqui

Browser other questions tagged

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