I get json results from a php file and I want to append them to a specific div section in another php file using ajax with jQuery.For now I have to results..Please help me in this
json results:
[
{
"title": "Welcome!",
"description": "The world has changed dramatically..",
"image": "img/article1.jpg"
},
{
"title": "Welcome 2!",
"description": "It is time for a new start..",
"image": "img/article2.jpg"
}
]
And the jQuery I am using is:
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: 'ajax_json.php',
type: 'post',
data: {tag: 'getData'},
dataType: 'json',
success: function(data){
if(data.success){
$.each(data, function(index, record){
if($.is_numeric(index)){
var row =
$("#output").append('<div class="article"><div>' + item.title + '</div><div style="width:200px;height:100px;background-image: url(' + item.image + ')"></div></div>');
});
}
})
}
}
});
});
Div section:
<div class="row top-buffer" id="output">
<div class="col-md-6" >
<img class="img-rounded" src="json image" alt="MyImage" width="550px" height="240px">
</div>
<div class="col-md-6">
<h3>json title</h3>
<p class="well">json description<p>
</div>
item.titlewhere is item. if want rewrite all. ask ?var row