jquery getting post action url

Jquery

Jquery Problem Overview


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 Solutions


Solution 1 - Jquery

$('#signup').on("submit", function(event) {
    $form = $(this); //wrap this in jQuery
    
    alert('the action is: ' + $form.attr('action'));
});

Solution 2 - Jquery

Try this ocde;;

var formAction = $("#signup").attr('action');
	

Solution 3 - Jquery

Clean and Simple:

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

      alert(this.action);
});

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondjburdickView Question on Stackoverflow
Solution 1 - JqueryAmy BView Answer on Stackoverflow
Solution 2 - JqueryVikram BiwalView Answer on Stackoverflow
Solution 3 - JqueryFereydoon BarikzehyView Answer on Stackoverflow