javascript - How to get POST variables in jQuery -
possible duplicate:
how get , post variables jquery?
i have following html:
<form action='.' method='post'>{% csrf_token %} <div class="parameters"> show <select name="earnings_filter"> <option value="all">total earnings</option> <option value="hd">hd earnings</option> <option value="sd">sd earnings</option> </select> <input type="submit" name="submit" class="submit float-right" value="submit" id="submit_financials"/> </div> </form> i need ajax call this, i'm triggering on:
$("#submit_financials").live('click', function(){ ... }); is there way variables submitted in post, example option selected (and there 10 other variables need get). or need use jquery selectors value of each?
$("#submit_financials").live('click', function(){ $.ajax({ url: '', // script url send method: 'post', // method of sending data: $('form').has(this).serialize(), // .serialize() make query string form inputs name , value datatype:'json', // expected data format returned server, may have else success: function(response) { // response contains data returned server } }); }); it better replace live() .on() if you're using jquery > 1.7 , it'd better if possible. can write it
$("#container").on('click', '#submit_financials', function(){ $.ajax({ url: '', // script url send method: 'post', // method of sending data: $('form').has(this).serialize(), // .serialize() make query string form inputs name , value datatype:'json', // expected data format returned server, may have else success: function(response) { // response contains data returned server } }); }); here #container point holder of #submit_financials belong dom @ page load.
Comments
Post a Comment