$.ajax({ type: 'GET', url:'index.php', success:function(msg){ //var result = JSON.parse(msg); console.log(typeof msg, msg); }, error: function(request) { console.log("ERROR", request); } });
Report that in the browser console.
string {"transaction": [{"id": "0", "btc": "0.2", "dtime": "25"}, {"id": "1", "btc": "0.2", "dtime": "25"}]}
A string comes to the success handler (which is odd, I thought that jQuery, in the absence of a dataType trying to determine the type of response data). After JSON.parse string is converted to an object. The function $().html(...) takes an html string or function. When a js object is served there, the innerHTML selected DOM elements is cleared.
success:function(msg){ var result = JSON.parse(msg); for (var i = 0; i < result.transaction.length; i++) { $('.result').append($("<div></div>").text(result.transaction[i].dtime)); } }
Option without JSON.parse :
dataType: "json", success:function(result){ for (var i = 0; i < result.transaction.length; i++) { $('.result').append($("<div></div>").text(result.transaction[i].dtime)); } }
msg? - Evgeny Ivanovmsgvariable itself? Is it empty? - Evgeny Ivanov.html()function - RifmaMan