0

I am trying to change the action of a form after a post. With this:

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

     })
    return false
  });

The result contains the form which has a default action="".

After this jquery, the action does not change. Is there something I am doing wrong? I pulled the changed from this post

I also tried clearing the form first:

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

The form returned from the result looks like this:

<div>
    <form id="edit-form" method="post" action="">{% csrf_token %}
        <fieldset></fieldset>
    </form>
</div>
Community
  • 1
  • 1
Atma
  • 29,141
  • 56
  • 198
  • 299

3 Answers3

0

Try this

$.post(url,data,function(result){
    $("#edit-form",$(result)).attr("action", "/edit-settings/");
    $(".page-added").append($(result));
});
omma2289
  • 54,161
  • 8
  • 64
  • 68
  • @Atma In my answer the form is edited before being appended, just do whatever you have to do before calling `.append()` – omma2289 Aug 03 '13 at 20:06
0

Try this and see what happens...

 $.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!');
     });
DevlshOne
  • 8,357
  • 1
  • 29
  • 37
0

Yes, but you forgot one thing!


Working example of form action change:
http://jsfiddle.net/NetworkNerd/QZeWn/1/

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

Try the code above, it should correctly modify the action attribute without any interruption. By the way, make sure the POST is working too.

1234567
  • 946
  • 6
  • 22
  • @Atma Change the order of the lines. I have a working example I'll show you in the edit i'm about to make. – 1234567 Aug 03 '13 at 19:40