JavaScript solves a scenario with a validated form two submit event (a page remains "Ajax implementation", a page commits and jumps)

Source: Internet
Author: User

Tag:eth   for   multipart   list    failed     success   ret   -name   value   

<form class= "form-horizontal" action= "/biz/patent/edit" method= "post" enctype= " multipart/form-data " data-toggle="validator " role="form " novalidate="true "  Id= "patenteditform" >               
<Buttonclass= "Btn btn-primary"type= "button"ID= "But_sub">Save</Button> <Buttonclass= "Btn btn-primary"type= "button">Save Return list</Button> <Buttonclass= "Btn btn-warning"type= "button"onclick= "window.location= '/biz/project/list ';">Return</Button>
</form>

$ (document). Ready (function(){    varButtonID; $(' #patentEditForm '). Validator (). On (' Submit ',function(e) {if(e.isdefaultprevented ()) {//handle the invalid form ...}Else {            //everything looks good!            if(ButtonID = = "But_sub"){                varFormData =NewFormData ($ ("#patentEditForm") [0]); $.ajax ({type:"POST", URL:"/biz/", Data:formdata, DataType:"JSON", NSync:false, Cache:false, ContentType:false, ProcessData:false, Success:function(date) {Switch(date.status) { Case1: $success ("Saved successfully!" ");  Break;  Case1009: $error ("Save failed!" ");  Break; default: $error ("No information submitted"); }}, Error:function() {$error ("No information submitted");                }                }); return false;    }        }    }); $(". Btn-primary"). Click (function() {ButtonID= $( This). attr ("id"); $(' #patentEditForm '). Trigger (' Submit '); });

$ (' #patentEditForm '). Validator (). On (' submit ') pass parameters (with global variables) between the processing methods of two events.
2. Use the. Trigger (' Submit ') method to trigger commits in JavaScript without the original form submission.


JavaScript solves a scenario with a validated form two submit event (a page remains "Ajax implementation", a page commits and jumps)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.