The type of the button 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 is an error posting the data to the server:" + error. responsetext);}});
The reason for the two submissions is that after the AJAX request has been executed, the behavior of submit is not blocked, so there are two ways to resolve it:
1, do not use the type as a Submit button, but use Type is button.
2. In $ (' #submit '). Click Function, the last line return False, you can block submit.
A note: Why do you want to embed English in the title? The reason is to be able to allow foreign netizens to query this article. Usually in Google to check the information, often refer to foreign netizens blog, help me solve a lot of problems, so I also want them to be able to refer to my written content. Of course, I can not all translated into English, so I try to stick the code, rely on the code to speak it.
The above mentioned is small set to introduce the button of the AJAX request when a click two times to submit the solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!