I need to display the JSON data in my PHP. The data is coming as a loop. The raw data looks like this :
[{
"count": 3,
"not": "New Intender details entered"
},{
"count": 3,
"not": "New Intender details entered"
},{
"count": 3,
"not": "New Intender details entered"
}]
My AJAX script is as follows:
function addmsg(type, msg) {
var obj = jQuery.parseJSON(msg);
$.each(obj, function(index, value) {
var count = value.count;
var not = value.not;
alert(not);
$('#msg_count').html(count);
$('#notification').html(not);
});
}
function waitForMsg(){
$.ajax({
type: "GET",
url: "notification/select.php",
cache: false,
timeout: 50000,
success: function(data){
addmsg("new", data);
setTimeout(waitForMsg, 1000);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
addmsg("error", textStatus + " (" + errorThrown + ")");
setTimeout(waitForMsg, 15000);
}
});
};
$(document).ready(function(){
waitForMsg();
});
My HTML is as follows:
<span id="msg_count"></span>
<span id="notification"></span>
The issue I am facing is that msg_count is showing fine. Now notification is a loop, which means it contains more than one record. When I am calling it through span, it's just showing one record. The rest of the records are not showing. I have given an alert(not) which is alerting all the records. I have only problem in showing in html as <span id="notification"></span>. Can anyone help me?
$.eachloop and when you first iterate over it does$('#notification')have the "not" value? Also after the loop iterates three times thehtmlfunction seems to override the previous value of the span.