jQuery replaceWith()在$ .post函数中不起作用

执行器

我正在尝试做一个待办事项列表类型的东西。在这里,我希望将新目标保存到数据库中,然后仅刷新具有相关列表的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. 
        });
    });
费利克斯·克林(Felix Kling)

请参阅

但由于标识应该是在HTML文档反正独特,可以替换$(this).closest('#goallist')使用$('#goallist'),完全忽略this

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ReplaceWith jQuery不起作用

来自分类Dev

jQuery .click()在replaceWith()之后不起作用

来自分类Dev

jQuery ReplaceWith()函数-表

来自分类Dev

jQuery-jQuery.replaceWith之后的`on`事件不起作用

来自分类Dev

jQuery replaceWith()$ this

来自分类Dev

jquery 中的 $.post 函数不起作用

来自分类Dev

replaceWith with jQuery Objects

来自分类Dev

jQuery对象的replaceWith

来自分类Dev

jQuery replaceWith保持onclick

来自分类Dev

ReplaceWith Jquery问题

来自分类Dev

jQuery .replaceWith()或.html()

来自分类Dev

jQuery replaceWith删除内容

来自分类Dev

jQuery .post()函数不起作用

来自分类Dev

在jQuery中使用.replaceWith删除HTML中的字符串

来自分类Dev

在jQuery中的replaceWith上添加SlideUp和Slidedown动画

来自分类Dev

在jQuery中使用.replaceWith删除HTML中的字符串

来自分类Dev

replaceWith(),remove()和empty()不起作用

来自分类Dev

Highchart在jQuery函数中不起作用

来自分类Dev

jQuery $(this)在函数参数中不起作用

来自分类Dev

jQuery函数在Laravel中不起作用

来自分类Dev

Onchange函数在Jquery中不起作用

来自分类Dev

javascript 函数中的 jquery 不起作用

来自分类Dev

按钮在 jQuery 函数中不起作用

来自分类Dev

jQuery .replaceWith在循环中冻结

来自分类Dev

jQuery .replaceWith无法正常工作

来自分类Dev

jQuery replaceWith并返回到原始

来自分类Dev

JQuery $.post 不起作用

来自分类Dev

jQuery .not()函数不起作用

来自分类Dev

jQuery函数不起作用