如何适应ajax请求?

如何适应ajax请求?,ajax,Ajax,我有这个代码,我想用答案数据替换“ul.hello list”内容。我正在努力 $.ajax({ type: "POST", url: "home/hello.php", data: { "action": "hello_action" }, success: function(datas) { if (datas) { $("ul.h

我有这个代码,我想用答案数据替换“ul.hello list”内容。我正在努力

 $.ajax({
        type: "POST",
        url: "home/hello.php",
        data: {
            "action": "hello_action"
        },
        success: function(datas) {
            if (datas) {
                $("ul.hello-list").fadeOut(); 
                // It doesn't work
                datas.fadeIn();
            }
        }
    });

Thxs

因此从您的评论来看,我相信您可以做到:

success: function(datas) {
    if (datas) {
        var $newContent = $(datas).hide();
        var $oldList = $("ul.hello-list");
        var $container = $oldList.parent(); // Replace this with whatever your container is

        $oldList.fadeOut();
        $newContent.appendTo($container).fadeIn();
    }
}

问题是,
datas
本身不是jQuery对象,因此不能对其调用jQuery函数。此外,它需要先连接到DOM,然后才能淡入。什么是数据?至少你需要把它包装成一个$()function.datas=“
  • 你好吗?”;