Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery getting post action url

Tags:

jquery

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!

like image 441
djburdick Avatar asked Mar 31 '10 05:03

djburdick


People also ask

How do I get a form action URL?

prop() returns the full action url: To use the action attribute of a form use: $( '#myForm' ). attr( 'action' ); like @JAAulde said.

How to POST data using jQuery?

The jQuery post() method sends asynchronous http POST request to the server to submit the data to the server and get the response. Syntax: $. post(url,[data],[callback],[type]);

How to make HTTP request in jQuery?

get() method requests data from the server with an HTTP GET request. Syntax: $. get(URL,callback);


2 Answers

$('#signup').on("submit", function(event) {     $form = $(this); //wrap this in jQuery      alert('the action is: ' + $form.attr('action')); }); 
like image 93
Amy B Avatar answered Sep 21 '22 14:09

Amy B


Try this ocde;;

var formAction = $("#signup").attr('action'); 
like image 41
Vikram Biwal Avatar answered Sep 24 '22 14:09

Vikram Biwal