在URL参数中添加一个jQuery选择器

add a jQuery selector to the URL parameter

本文关键字:一个 jQuery 选择器 URL 参数 添加      更新时间:2023-09-26

是否可以在AJAX请求后向URL参数添加jQuery选择器?这是我的完美工作代码:

$.ajax({
    type : "POST",
    url : "load_page.php",
    data : 'page=' + url,
    success : function(msg) {
        if (parseInt(msg) != 0)//if no errors
        {
            $content.fadeIn(200, function() {
            $('#content').html(msg);
            });
        }
    }
});
//load the returned html into pageContent 

我知道通过.load()(或链接)是可能的:

$("# content'").load("demo_test.txt #sub.content");

但通过$('#content').html(msg);有可能吗?

其他信息:我试图只获取<div id=”sub-content”>

是的,在附加数据之前只需过滤数据即可。

var $content = $("#content").empty();
$("<div>").html($.parseHTML(msg)).find("#sub").appendTo($content);