表单操作不会改变jquery帖子

时间:2013-08-03 19:13:35

标签: jquery html html-form

我试图在帖子后更改表单的操作。有了这个:

 $.post(url,data,function(result){
        $( ".page-added" ).append(result);
        $("#edit-form").attr("action", "/edit-settings/");

     })
    return false
  });

结果包含具有默认操作=“”的表单。

在此jquery之后,操作不会更改。有什么我做错了吗?我从this post

取消了更改

我还尝试先清除表单:

      $("#edit-form").removeAttr("action").attr("action", "/edit-settings/");

从结果返回的表单如下所示:

<div>
    <form id="edit-form" method="post" action="">{% csrf_token %}
        <fieldset></fieldset>
    </form>
</div>

3 个答案:

答案 0 :(得分:0)

试试这个

$.post(url,data,function(result){
    $("#edit-form",$(result)).attr("action", "/edit-settings/");
    $(".page-added").append($(result));
});

答案 1 :(得分:0)

试试这个,看看会发生什么......

 $.post(url,data,function(result) {
     }).done(function(result) {
        alert('We got back an acceptable result and processing!');
        $( ".page-added" ).append(result);
        $("#edit-form").attr("action", "/edit-settings/");
     }).fail(function() {
        alert('We got back a bad result and failed!');
     }).always(function() {
        alert('We're done with the AJAX routine!');
     });

答案 2 :(得分:0)

是的,但你忘了一件事!


表单操作更改的工作示例:
http://jsfiddle.net/NetworkNerd/QZeWn/1/

$.post(url,data,function(result){
    $(".page-added").append(this);
    $("#edit-form").attr("action", "/edit-settings/index.php");
 });
});

尝试上面的代码,它应该正确修改action属性而不会中断。顺便说一句,确保POST也正常工作。

相关问题