Reputation:
I am trying to submit various forms on the same page via jQuery/AJAX, it is for an admin site where you edit users so the url/action for the form gets generated dynamically. e.g
/user/limit/update?userId=7
or
/user/address/update?id=2
.
is there a way find the forms url/action, store it in a variable and pass it the the url in the ajax function?
hopefully the example will make it more obvious.
the generated form tag is
<form action="/user/update?id=3" method="post" accept-charset="UTF-8" enctype="application/x-www-form-urlen" id="idfff">
and updated ajax from the suggestion is
$("#user-submit").click(function() {
$.ajax({
type: "post",
url: $('#idfff').attr('action'),
data:$('#user-update').serialize(),
success: function() {
$("<div class='update-success'>Details updated</div>").insertAfter("#user-submit");
}
});
return false;
});
Hopefully I have explained my problem correctly but please let me know if you require further info.
Thanks
Upvotes: 1
Views: 184
Reputation: 3668
Something like the following?
$("#yourForm").attr("action");
Upvotes: 0
Reputation: 3026
Use attr()
function on the form element to get action attribute value. In your example it should be something like this: url: $('#limits').attr('action')
Upvotes: 2