Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a portion of the ajax html response

My ajax (jquery) response (html) gives me a whole junk of html source code since it fetches the enrite page.

The response is somewhat like below:


<html&gt
<head&gt
...
...
</head&gt
<body&gt
.
.....
.

.......

<div id="content"&gt
    content i want to extract
</div&gt
.............
..........
.............

</body&gt
</html&gt

I need help with the following:

1) Is it possible to read just whatever is between the <div id='content'></div>? if yes, how?

2) if #1 is not possible, how could I extract just the content from the <div id='content'></div>?

The code I tried:


    /*Ajax*/
    $jq(function(){
    alert ("Doc ready");
        $jq("#content a.next-page").bind("click", function(e){
            alert ("Hey!");
            /*Make the call*/
            $jq.ajax({
                url: "/page/2",
                type: "get",
                cache: false,
                data: "",
                error: function(){alert ("No data found for your search.");},
                success: function(results){
                    //$searchPanel.find("tbody").empty().append(results);
                    //$searchPanelHolder.css({"display":"block"});
                    alert (results.find("div[id='content']").html());
                    e.preventDefault();
                }
            });
            e.preventDefault();
        });
    });

Any help on this is much appreciated

Many thanks, Racky

like image 350
racky Avatar asked Nov 14 '22 09:11

racky


1 Answers

what about this?

$("#content", results).html()
like image 191
yedpodtrzitko Avatar answered Dec 07 '22 23:12

yedpodtrzitko