简体   繁体   中英

jquery, ajax and submitting a form

I am trying to make all the forms in the page to do something when they are submitted and to prevent their default behavior using this jQuery code:

$("form").not("#loginf").submit(function (){
    event.preventDefault();
    var inputs = $(this).serialize();
    $.ajax({
      url: "pages/"+page+".php",
      type: "POST",  
      data: inputs+'&action='+param,
      cache: false
    }).done(function( html ) {
        update(html);
        rs();
    }).fail(function (){
        window.location = "/CMS/";
    });
});

and this html form (just 1 of them):

<form method="POST" name="cpass">
    <span class="brow"><span class="label">סיסמא ישנה:</span><input type="password" name="oldp" /></span>
    <span class="brow"><span class="label">סיסמא חדשה:</span><input type="password" name="newp" /></span>
    <span class="brow"><span class="label">וידוא סיסמא:</span><input type="password" name="rnewp" /></span>
    <span class="brow"><input type="submit" name="cpasssub" value="שנה סיסמא"/></span>
</form>

The problam is that the jQuery function doesn't even get executed (i checked by placing an alert there).

What is wrong here?

您错过了提交中的event参数

  $("form").not("#loginf").submit(function (event){

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM