jquery getting post action url

2020-05-19 03:41发布

I'm trying to access the post target action in a jquery function.

example:

<form action="/page/users" id="signup" method="post">

I'd like to access the "action" part - "/page/users" in this case.

$('#signup').live("submit", function(event) {
    // get this submitted action
}

Seems like I'm missing something very simple. I see the value in the dom but don't know where it's stored in jquery.

Thanks!

标签: jquery
3条回答
▲ chillily
2楼-- · 2020-05-19 03:59

Clean and Simple:

$('#signup').submit(function(event) {

      alert(this.action);
});
查看更多
Luminary・发光体
3楼-- · 2020-05-19 04:01
$('#signup').on("submit", function(event) {
    $form = $(this); //wrap this in jQuery

    alert('the action is: ' + $form.attr('action'));
});
查看更多
家丑人穷心不美
4楼-- · 2020-05-19 04:05

Try this ocde;;

var formAction = $("#signup").attr('action');
查看更多
登录 后发表回答