A bug in the combination of ajax and bootstrap

Source: Internet
Author: User

A bug in the combination of ajax and bootstrap

The front-end is like this.

The original logic is to click submit, the modal box appears, and then click comment.Submitting data to the backend Using ajax seems okay, but the two buttons are nested with each other,

(The code is incomplete)

Error Code

 

$ ("# Reply button "). on ('click', function () {// obtain the information of the reply object; $ ("comment in the modal box "). on ('click' function () {// obtain the nickname and content in the pop-up box. ajax ({Transfer Data ;});)};)};

 

Then the problem arises. We can see this effect.

 

  

 

Comments 1 are normal, comments 2 are displayed twice, and comments 3 are tested three times

This problem lies in the nesting of two button on click events.

PressExternal button replyIt starts to listen to whether the internal button comment is pressed, the second time the external button is pressed, the first time the external button is clicked within the listener, the second time the external button is also listening, so the server will post the data twice, and so on ........

Solution,Separate the click events of two buttons

Correct code

$ ("# Reply button"). on ('click', function (){
// Obtain the response object information;
)};

$ ("Comment in the pop-up box"). on ('click' function (){
// Obtain the nickname and content in the pop-up box
. Ajax ({
Transmit data;
});

)};
 

 

 

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.