The button type on the page is submit: <input type = "Submit" value = "CREATE" id = "Submit"/>
Ajax requests in jquery are:
$ ( Function (){
$ ('# Submit'). Click ( Function (){
VaR Creategenreform = $ ('# creategenreform ');
If (Creategenreform. Valid ()){
VaR OBJ = {
Name: $ ('# name'). Val (),
Description: $ ('# description'). Val ()
};
VaR Jsonserialized = JSON. stringify (OBJ );
$. Ajax ({
Type: "Post ",
URL: creategenreform. ATTR ('action '),
Datatype: "JSON ",
Contenttype: "application/JSON; charset = UTF-8 ",
Data: jsonserialized,
Success: Function (Result ){
Alert (result. Message );
},
Error: Function (Error ){
Alert ("There was an error posting the data to the server:" + error. responsetext );
}
});
}
});
});
The reason for two submissions is that after the Ajax request is executed, the submit action is not blocked, so there are two solutions:
1. Do not use buttons whose type is submit type, but use buttons whose type is button.
2. In the $ ('# submit'). Click function, add a return false line;To block submit.