Help, i want to do looping when the data is displayed to the div tag as the following code :
function GetDataFromServer() {
var url = "http://bertho.web.id/curl/services21/DataReadNP.php";
JSONP.get(url, {}, function(response){
var listItem, container, dataList = document.getElementById("dataList"), str = "", str2 = "";
for ( var i = 0; i < response.length; ++i ) {
str += response[i].title;
str2 += response[i].fetch_date;
}
listItem = document.createElement('div');
listItem.setAttribute('data-bb-type', 'item');
listItem.setAttribute('data-bb-img', 'images/icons/icon11.png');
listItem.setAttribute('data-bb-title', str);
listItem.innerHTML = str2;
container = document.createElement('div');
container.appendChild(listItem);
bb.imageList.apply([container]);
dataList.appendChild(container.firstChild);
if (bb.scroller) {
bb.scroller.refresh();
}
});
}
To display the list to the screen :
function dataOnTheFly() {
document.getElementById('waiting').style.display = 'none';
GetDataFromServer()
}
The data I want is displayed on the screen, but do not fit what I wanted.
Please see pictures below :
http://s13.postimage.org/68w2zfmh3/data_BB.png
I want to list this data looping until all the data on the server is taken.
How do I to get the results I want?
Pulling up the URL given in your question, your data looks like this:
This is a
JSONresponse, not aJSONP— they are similar, but different. I’m not sure what yourJSONPfunction does, so I can’t tell you exactly how to proceed.At some point, you need to run
JSON.parse()on the data you receive. Your library may nor may not do this for you. Iftypeof response === "string"then it hasn’t.Once you have the
JSONdecoded to an object, then it is just a simple matter of looping