jQuery:重用提交功能

Hey guys i have looked as much as i could and i could not find an answer, i am creating an admin interface that has forms all over the place and i would like to use the same jquery code for all of them, i have some code that is getting the job done but i would like to know if there is a more efficient way to do it. here is the code

    function submitForm( formname ) 
{
  $.ajax
  ({
    type:'POST', 
    url: 'session.php', 
    data: $(formname).serialize(), 
    success: function(response) 
    {
      if( $('#message_box').is(":visible") ) 
      {
        $('#message_box_msg').html ('') 
        $('#message_box').hide();
      }
      $('#message_box').slideDown();
      $('#message_box_msg').html (response);      
    }
  });
return false;
}

Now my forms look something like this:

<form id="adminForm" action="session.php" method="post" onsubmit="return submitForm('#adminForm');">

Now my question is... is there a simpler way to do this, like without having to provide the submitForm() function with the form id every time?

Thanks in advance!

查看全部
weixin_33695450
weixin_33695450
2012/06/28 02:56
  • dynamic
  • ajax
  • javascript
  • forms
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

2个回复