Button Ajax request when clicked two times submitted solution _ajax related

Source: Internet
Author: User

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!

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.