我想做一个待办事项列表类型的事情。 在这里,我希望将新目标保存到数据库,然后仅对具有相关列表的div进行刷新,并显示添加了新目标的列表。
数据库更新正常,新的列表项返回新的HTML就好了,但 .replaceWith()似乎不工作。什么都没发生。
它的工作原理是功能之外,而不是里面的话,我不知道为什么。
$('.addGoal').submit(function(event){
var listid = $(this).attr('id');
var desc = $(this).children('.goalinput').val();
event.preventDefault();
if(desc == "") {
console.log("empty!");
return;
}
var posting = $.post("updatedata.php", { what :'addgoal', id: listid, data: desc});
posting.done(function(data){
console.log("saved!" + data); //this works, the updated html is being returned
$(this).closest('#goallist').replaceWith("Returned data goes here"); //this works outside of this function but not inside of it.
});
});
谢谢!它不仅现在完美地工作,而且我总体上受到很高的教育。 – Cactuar