I’m using this code
$.post("assets/scripts/chat/load_convos.php",{}, function(data) {
$.each(data, function(index, value) {
alert(value);
});
,and the return of the data is [57,49] but it just doesn’t do anything… If I replace the data just after the $.each( with [57,49] it works but not with the data in its place.
I’m not the best with Javascript so all help is much appreciated.
What do you mean with “the
datais[57,49]” ?My guess is, that you expect a (JSON)-object but you just receive a string. My second guess is that jQuery interpretates the result the wrong way and does not identify the return as JSON-String and hence, does not implicit
JSON.parseit.Check the content-types of the request. Try to call
data = JSON.parse(data);manually before calling theeachloop. Actually jQuery should be able to identiy that string as a JSON result itself, so I’m also wondering which jQuery version you use.Another shot you might have is to call
.getJSON()instead of.post()directly.