Error while retrieving json information with ajax

Asked

Viewed 70 times

0

I am making a JSON request, which returns the results, but not on the date, but on the ajax error.

 var url = window.location;
var id = url.toString().split("=")[1];
var msg = '';
$.ajax({
    type: 'POST',
    url: 'load-data.php?id='+id,
    dataType: 'json',
    success: function(data) {
         msg = data;
         alert(msg)

    },
    error:function(e){
        console.log(e)
    }
});

As you can see underneath inserir a descrição da imagem aqui

I just don’t understand why the result appears in the ajax error.

  • You need to look at the console and know what the status is being returned.

  • 200, if it is pag status, that is a ok

  • Check if the type of data ajax is like this; dataType: "json"

  • Yes, you are Leonardo

  • Why does it say that the result is in error? I see in responseText!

  • 1

    Have you tried using other types to see if it has any different effect? You can use text json or just text

  • In the text, speaking truth, it worked

  • And in text json, same thing as the error

  • How is the return of your PHP ?

  • Do an echo json_encode in a select function

  • 1

    I’ll leave dataType : "text" even, it worked

Show 6 more comments
No answers

Browser other questions tagged

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