Javascript jQuery:如何在回调后数据中找到当前对象?

Javascript jQuery:如何在回调后数据中找到当前对象?,javascript,jquery,ajax,post,Javascript,Jquery,Ajax,Post,我有一个ajax post函数: $(".button").click(function(){ var postData = ..some data.. var targetDiv = $(this).closest(".someDiv"); $.post(doucemnt.location, postData, function(data) { content = ... How to find targetDiv inside data h

我有一个ajax post函数:

$(".button").click(function(){
     var postData = ..some data..
     var targetDiv = $(this).closest(".someDiv");

     $.post(doucemnt.location, postData, function(data) {

         content = ... How to find targetDiv inside data here? ..

         targetDiv.html(content);
     });
});
从post返回的数据将是整个网页,我需要过滤它,只得到我想要刷新的div。我不想按ID或类使用任何选择器,因为每个div中都有许多someDiv和button的副本,所以我只想获取当前单击的button的div对象,并在回调数据中搜索它


有可能吗?

我不确定我是否完全理解你的问题,所以请原谅我有点离题。 我想如果没有别的事情的话,这可能会给你一些想法。我将解析响应数据,寻找特定的“钩子”。然后只返回那块数据

JavaScript:


targetDiv的作用域允许您在回调中使用它当您使用代码时会发生什么?在我看来没问题,你是什么意思,从DOM中获取的元素和返回到ajax函数的字符串中存在的元素不是同一个元素?问题是我无法获取内容,有没有一种方法可以在数据中找到对象而不使用id或类,可能通过对对象本身的引用或处理程序?啊,因此,看起来您有一个页面,并且正在尝试加载另一个页面,该页面具有与此页面相同的plaecholder代码,但是您希望将此页面的html替换为从中加载它的html。您不能使用ID,因为您必须一遍又一遍地从这些div和按钮列表中删除垃圾邮件或其他内容。。。正当
$('.button').click(function (event) {

// This would be your (real) ajax call.
doAjaxPost('www.location.com', postData, function (response) {
    var $refresh = $($.parseHTML(response)).filter('#refresh');
        $('#content').html($refresh);
    });
});