0
I am making a request to my Servlet and taking the json data according to the code below:
$(document).ready(function(){
$.post("MesaController",function(response){
$.each(response,function(i,v){
$("<button>")
.text(v.nome).appendTo($("#mesas"));
});
//console.log(response);
});
});
However the following error occurs:
jquery.min.js:2 Uncaught TypeError: Cannot use 'in' operator to search
for 'length' in [{"id":1,"nome":"mesa 1"},{"id":2,"nome":"mesa 2"},
{"id":3,"nome":"mesa 3"}]
at w (jquery.min.js:2)
at Function.each (jquery.min.js:2)
at Object.success (mesa.js:8)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at A (jquery.min.js:4)
at XMLHttpRequest.<anonymous> (jquery.min.js:4)
has tried to make JSON.stringfy from Sponse?
– Adelino Jose Ngomacha
What happens if you put
console.log(typeof response, JSON.stringify(response));
before the line$.each(response...
?– Sergio
When I put the command you entered Adelino string " [{"id":1,"name":"table 1"},{"id":2,"name":"table 2"}, {"id":3,"name":"table 3"}]"
– ayowole agbedejobi