Hi so currently I have a set of codes which dynamically creates HTML elements through AJAX using an external JSON data. When I created this, I wanted to store my data in an external file rather than in a database.
However, I now need to store them in mySQL so I was wondering how I can still dynamically create the HTML elements like this but now the data will be from mySQL instead of retrieving it from an external JSON file. I'm still quite new to this so I am really confused as to how to tackle this situation.
This is what my current code looks like:
<script>
$.ajax({
url : "CR/CR_Data/CR_QuickLookData.json",
type : "post",
contentType:"application/json",
success : function(list){
var divCol = "<div class='col-sm-4 col-md-4'>";
var divWell = "<div class='well' style='position:relative'>";
var divClose = "</div>";
console.log(list);
list.forEach(function(obj, index) {
//console.log(obj);
var title = "<h5>" + obj.title + "</h5>";
var linkStart = "<a href='" + obj.imagePath + "' rel='lightbox' title='" + obj.title + "'>"
var image = "<img data-toggle='tooltip' data-placement='left' class='wellImg' title='Click to enlarge image' src='" + obj.imagePath + "'/>"
var desc = "<p>" + obj.desc + "</p>";
var linkEnd = "</a>";
var div = divCol +
divWell +
title +
linkStart +
image +
desc +
linkEnd +
divClose +
divClose;
$("#CR").append(div); // insert the div you've just created
})
}
});
</script>
JSON Data:
[
{
"team":"Team Name",
"title":"Title",
"filePath":"#",
"imagePath":"image path",
"desc":"Data Description"
},
{
"team":"Team Name",
"title":"Title",
"filePath":"#",
"imagePath":"image path",
"desc":"Data Description"
},
{
"team":"Team Name",
"title":"Title",
"filePath":"#",
"imagePath":"image path",
"desc":"Data Description"
}
]
When I tried pulling my data using PHP and encoding it to JSON, it gave me this result and it did not create any of the HTML elements needed.