How To Get Post Variables In Jquery March 27, 2024 Post a Comment Possible Duplicate: how to get GET and POST variables with JQuery? I have the following HTML: {% csrf_token %} , function(){ $.ajax({ url: '', // script url to sendmethod: 'POST', // method of sendingdata: $('form').has(this).serialize(), // .serialize() make query string with form inputs name and valuedataType:'json', // expected data format returned from server, you may have something elsesuccess: function(response) { // response contains data returned from server } }); }); CopyIt would be better replace live() with .on() if you're using jQuery > 1.7 and it'd be better if possible. So you can write it$("#container").on('click', '#submit_financials', function(){ $.ajax({ url: '', // script url to sendmethod: 'POST', // method of sendingdata: $('form').has(this).serialize(), // .serialize() make query string with form inputs name and valuedataType:'json', // expected data format returned from server, you may have something elsesuccess: function(response) { // response contains data returned from server } }); }); CopyHere #container point to holder of #submit_financials that belong to DOM at page load.Solution 2: If all the values are in input elements on the form... $("#formId").serialize() CopySolution 3: You could serialize the form and send to the server page$.post("yourServerPage.php", $("form").serialize(),function(data){ //Do whatever with the result from ajax server page. }); CopySolution 4: How about creating several input values of type hidden<inputtype="hidden"id="sample_id" value="SOMETHING" /> Copygive them ids and acces the data inside using:Baca JugaHow To Call Ajax In A Webpage From Python Script Without Browser Emulation Or Headless Brawser?Output Log File Through Ajax In DjangoDjango Render New Result Values From Ajax Request To Html Page$('#sample_id').val() CopySolution 5: Unfortunately, POST variables are communicated in the request from the client to the server, but they are not automatically included in the response from the server back to the client. This is one of the things that sets them apart from GET variables.If your data isn't excessively long, you may want to switch to the GET method instead. You can then retrieve the variables using a function like one listed in this question: How can I get query string values in JavaScript? Alternatively, if you have access to the server-side code, you could include these variables in HTML returned; however this is another question entirely :) Share You may like these postsEel Function Returns NullFlask|Jinjia2|Javascript: Passing Flask Template Variable Into JavascriptD3 Array Input Line Graph ExampleBottlepy - How To Access Bottle Arguments {{var}} From Javascript? Post a Comment for "How To Get Post Variables In Jquery"
Post a Comment for "How To Get Post Variables In Jquery"