0
I get this return with json_encode by php but I am not able to read it in ajax Success, what I am doing wrong?
{"id":"1","id_pesquisa":"3","id_pergunta":"7","id_resposta":"31","mostrar":"1","ocultar":"2"},
{"id":"2","id_pesquisa":"3","id_pergunta":"8","id_resposta":"31","mostrar":"2","ocultar":"1"}
var direcao = $.ajax({
type : 'get',
url: 'dadosPS.php?ps=direcionamento',
dataType: 'JSON',
beforeSend: function (xhr) {
},success: function (data, textStatus, jqXHR) {
for(var i = 0;i<data.length;i++){
console.log(data[i].id);
}
},error: function (jqXHR, textStatus, errorThrown) {
}
});
what error it shows you on the console ?
– 13dev
Retorna este erro :Uncaught TypeError: Cannot use 'in' operator to search for '185' in {"id":"1","id_pesquisa":"3","id_pergunta":"7","id_resposta":"31","mostrar":"1","ocultar":"2"}{"id":"2","id_pesquisa":"3","id_pergunta":"8","id_resposta":"31","mostrar":"2","ocultar":"1"}
– Carlos Lopes
True, if there are any errors json might not show correctly, check this line 185 and analyze this word in
– adventistaam
If this is JSON.. it is WRONG! Use jsonlint to validate your JSON.
– William Aparecido Brandino
In addition to fixing your php file, it also tries to use javascript
dataType: 'json'
, JSON for json (lower case)– adventistaam
Well I made the corrections but nothing to work, as William said must be wrong this JSON. @Williamasimiliar, which would be the correct format to read?
– Carlos Lopes
Install the Postman and paste this url there to see or that happens the glue in your browser itself and see what returns
– adventistaam
@Carloslopes In this case, must be in square brackets.
– William Aparecido Brandino