jQuery:如何在Post回调数据中查找当前对象
jQuery: How to find current object in Post callback data?
我有一个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"answers"button"的副本,所以我只想获得当前单击按钮的div对象,并在回调数据中搜索它。
这可能吗?
我不确定我是否完全理解你的问题,所以如果我偏离了,请原谅我。我认为(如果没有别的(这可能会给你一些想法。我将解析响应数据,寻找特定的"钩子"。然后只返回那块数据。。。
JavaScript:
$('.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);
});
});
JSFiddle
相关文章:
- Javascript:根据对象的嵌套数组中的值,在数组中查找对象的索引
- 正在数组中查找对象
- 在prototypejs中查找对象的类
- 通过知道对象的id在JSON中查找对象
- Javascript在JSON中查找对象(我使用Angular)
- 查找对象数组是否包含其中一个标记的最快方法
- 如何将查找对象值传递到FetchXml查询中
- JavaScript-通过类似的属性查找对象,并将其推送到一个新的数组中
- 通过匹配 - Javascript/AngularJS 中的参数来查找对象
- 正在查找对象集合的最大值
- 根据Angular JS中的属性值在列表中查找对象
- 在下划线中的对象中查找对象中的重复项
- 如何使用正则表达式查找对象成员名称
- 通过包含的字符串查找对象
- 在 Firebase 中通过对象的唯一 id 查找对象
- 在 javascript 中查找对象的类型
- 查找对象树中特定字段值的所有出现
- 如何在javascript数组中按键和值查找对象的索引
- 使用 Javascript/React.js 查找对象的数组索引
- 查找对象数组(Angularjs)中是否存在值