code_junkie

Submit form using AJAX and jQuery

Nov 13th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <form method="get" action="page.html">
  2. <input type="hidden" name="field1" value="value1" />
  3. <input type="hidden" name="field2" value="value2" />
  4. <select name="status">
  5. <option value=""></option>
  6. <option value="good">Good</option>
  7. <option value="bad">Bad</option>
  8. </select>
  9. </form>
  10.  
  11. $("select").change(function(){
  12. $.get("page.html?" + serializeForm());
  13. });
  14.  
  15. $(document).ready(function() {
  16. $('#myForm1').ajaxForm();
  17. });
  18.  
  19. $("select").change(function(){
  20. $('#myForm1').ajaxSubmit();
  21. });
  22.  
  23. $(document).ready( function() {
  24. var form = $('#my_awesome_form');
  25.  
  26. form.find('select:first').change( function() {
  27. $.ajax( {
  28. type: "POST",
  29. url: form.attr( 'action' ),
  30. data: form.serialize(),
  31. success: function( response ) {
  32. console.log( response );
  33. }
  34. } );
  35. } );
  36.  
  37. } );
  38.  
  39. $("select").change(function(){
  40. $.get("/page.html?" + $(this).parent("form").find(":input").serialize());
  41. });
Add Comment
Please, Sign In to add comment