Tuesday, April 5, 2011

extracting the post parameters from a form using javascript/jQuery before submission

how can i get the parameters of any form being submitted with method=post before it's submitted using javascript(preferably jQuery). What i am trying to do is get the post parameters and submit it to an alternate loacation. i was using

 $('form').submit(function(){
            alert('action=  '+$(this).attr("action"));
            alert('serialized string'+ $(this).serialize());
            return false;
        });

but it works only with get request i want to extract the parameters from the post requests too .

From stackoverflow
  • Something like this works for me

    $('#form').submit(function(){
            $.post(your_location, $(this).serialize());
        return false;
      });
    

    You can use the any other Ajax method you like if you don't want to use $.post(). You can also include a callback method to handle whatever your ajax call returns.

0 comments:

Post a Comment