1

ファイルのコンテンツを取得するために単純な ajax リクエストを実行しているだけですが、実際の<body>ものを取得しようとすると、常に何も返されません。

jQuery.ajax(location).done(function(response) {
    // RETURNS []
    console.log(jQuery(response).find('body'));

    // <body class="html ...">
    // RETURNS []
    console.log(jQuery(response).find('.html'));

    // When I try to get any other div it just works
    // RETURNS THE DIV
    console.log(jQuery(response).find('#header'));
})
4

1 に答える 1

1

jQuery(response)はhtmlheadbodyタグを取り除きます

ボディ コンテンツを余分な div でラップして探す必要があります。

編集:

jQuery( string ) は、文字列を解析して、セレクターまたは html フラグメントであるかどうかを確認します。それが html フラグメントの場合、文字列はhtmlhead、およびbodyタグをサポートしない空の div に挿入されるため、それらは取り除かれます。

于 2012-09-07T10:03:22.493 に答える