3

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);
                    });
                }
            }
        });
    });
});

2 Answers 2

3

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

a single:

$("#result").load("filename.html #elementid_inside_filename");  

Would suffice. (unless the file is in another domain)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.