I have a Google Instant style search script written in jQuery which I want to pull results from a PHP script. I know my script currently needs JSON as the output but I want it to output PHP generated HTML instead. How can I do this?
Here is my code:
$(document).ready(function(){
$("#search").keyup(function(){
var search=$(this).val();
var keyword=encodeURIComponent(search);
var yt_url='http://www.SITEURL.com/search.php?action=SEARCH&keyword='+keyword+;
window.location.hash=keyword;
$.ajax({
type:"GET",
url:yt_url,
dataType:"jsonp",
success:function(response){
$("#result").html('');
if(response.SearchResponse.Web.Results.length){
$.each(response.SearchResponse.Web.Results, function(i,data){
var title=data.Title;
var dis=data.Description;
var url=data.Url;
var final="<div class='webresult'><div class='title'><a href='"+url+"'>"+title+"</a></div><div class='desc'>"+dis+"</div><div class='url'>"+url+"</div></div>";
$("#result").append(final);
});
}
}
});
});
});
Just use
dataType:"html",
In your $.ajax call. The result will be returned as plain text, so if you just want to display it you can
success:function(response){
$("#result").html(response);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With