AmitKumar AmitKumar - 1 month ago 16
Ajax Question

This json object and how to make list element in page the below is code for Product.php

{"id":"3","thumb":"thumb/IMG_0142.jpg","original":"original/IMG_0142.jpg","name":"PE-1"}


This my json object i will print on my product page but how can acheieve the list element in that looks like this

<li title="<?php echo $row['name'] ?>">
<a href="<?php echo $row['original']?>" rel="prettyPhoto[gallery1]">
<img src="<?php echo $row['thumb']?>" alt="Code ID" title="fash"/>
</a>


This php code but want print json data in
li
element Please i trying my best but doesn't get actual expected output

This search result of ajax call in json format which can display on product page in above code but how can achieve this code ?

Sorry for wrong question.

$(document).ready(function(){
$('#search_text').keyup(function(){
$("#gridArea ul li").hide();

var txt = $(this).val();
if(txt != '')
{
$.ajax({
url:"fetch.php",
method:"post",
data:{search:txt},
dataType:"text",
success:function(data)
{
//$('#result').html(data);
var=<li title="data.name">
<a href="data.original" rel="prettyPhoto[gallery1]">
<img src="data.thumb" alt="Code ID" title="fash"/>
</a>
}

});
}
else
{
$('#result').html('');

$("#gridArea ul li").show();
}
});
});

Answer

Do the following in your ajax success function

 var result='<li title="'+data.name+'"><a href="'+data.original+'"  rel="prettyPhoto[gallery1]"><img src="'+data.thumb+'" alt="Code ID" title="fash"/></a>';
 $('#result').html(result);