JQuery selectors in ajax response line, which is a complete html page

I am trying to get some page details (page name, image on the page, etc.) of an arbitrarily entered URL / page. I have a back-end proxy script that I use via ajax GET to return the full HTML address of the remote page. As soon as I get the ajax response back, I try to run several jQuery selectors to extract page details. Here's a general idea:

$.ajax({
        type: "GET",
        url: base_url + "/Services/Proxy.aspx?url=" + url,
        success: function (data) {
            //data is now the full html string contained at the url

            //generally works for images
            var potential_images = $("img", data); 

            //doesn't seem to work even if there is a title in the HTML string
            var name = $(data).filter("title").first().text();

            var description = $(data).filter("meta[name='description']").attr("content"); 

        }
    });

Sometimes use $("selector", data)seems to work, while at other times it $(data).filter("selector")works. Sometimes it doesn’t work. When I just check the contents $(data), it seems that some nodes go through, but some just disappear. Does anyone know a consistent way to run selectors on a full line of HTML?

+5
1

, w/r/t, , , . HTML, , .

, $(data), data:

$.ajax({
    type: "GET",
    url: base_url + "/Services/Proxy.aspx?url=" + url,
    success: function(data) {
        var $data = $(data);

        //data is now the full html string contained at the url
        //generally works for images
        var potential_images = $("img", $data);

        //doesn't seem to work even if there is a title in the HTML string
        var name = $data.filter("title").first().text();

        var description = $data.filter("meta[name='description']").attr("content");
    }
});
+2

All Articles