0

I know that many topics exist about that, but I didn't find a solution to my issue. I make an AJAX request, and I'd like to parse the result, and inject it in a table in my page.

$.ajax( {
        type    :   "GET",
        url     :   "http://keyserver.gingerbear.net/pks/lookup?",
        data    :   "search=john.smith@gmail.com&fingerprint=on&op=index",
        dataType:   "html",
        success :   function(resultat){
                        $(resultat).ready(function() {
                                $('pre',$(resultat).html()).each(function(){
                                var htmlString = $(this).html();
                                console.log("Key ID : "+/0x[a-z0-9]{16}/i.exec(htmlString));
                                console.log("User : "+$(this).find('a:eq(1)').text());
                                console.log("Bits : "+/[0-9]{4}[RD]/.exec(htmlString));
                                console.log("Data : "+/[0-9]{4}-[0-9]{2}-[0-9]{2}/.exec(htmlString));
                                console.log("Fingerprint : "+/Fingerprint=(.*)/.exec(htmlString));
                                });
                        });
                    },
        // Blabla
    } );

I saw here the beginning of a solution. For example I can do console.log($(resultat).find('a')) and I have the content of the first , but console.log($(resultat).find('pre')) doesn't work...

4

1 回答 1

0

首先,您应该使用jQuery load将外部内容加载到元素中。

要回答您的问题,您不能使用在表示您正在搜索的元素时find查找pre标记(在这种情况下)。但是,您可以搜索父元素,然后从父元素中使用。$(this)prepre.find

var parent = $(this).closest("#parentDiv");
var preChild = parent.find("pre").first();
于 2013-04-11T14:00:35.693 回答