How to disable the button to avoid repeated jquery. Ajax requests

Source: Internet
Author: User

Use jquery. when Ajax requests data, to avoid repeated requests, You need to disable the request submission button. Generally, this is relatively simple. You only need to add the disabled attribute to the button. A test instance is written below, describes how to disable a button.
InstanceCodeAs follows:
1. Include the file part and reference the jquery File

    1. <SCRIPT src = "http://code.jquery.com/jquery.js” type =" text/JavaScript "> </SCRIPT>

Ii. html Section

<Button id = "test"> test </button>

<Div id = "result"> </div>

Define a test button and a result display Div Layer

Iii. Javascript

 

<SCRIPT type = "text/JavaScript">
Jquery (document). Ready ( Function (){
Jquery ("# test"). Click ( Function (){
Jquery ( This ). ATTR ({"disabled": "disabled "});
Biuuu. _ Ajax ();
});
});
VaR Biuuu = {};
Biuuu. _ Ajax = Function (){
Jquery. Ajax ({
URL: “biuuu.html ",
Success: Function (HTML ){
Jquery ("# result"). append (HTML );
}
});
Jquery ("# test"). removeattr ("disabled ");
}
</SCRIPT>

 

When you click the test button, use jquery (this ).ATTR({"Disabled": "disabled"}) to disable the test button, add a disabled attribute to the test button, and then execute biuuu. _ Ajax () request. when the request is complete, use jquery ("# test ").Removeattr("Disabled") statement to remove the disabled button attribute, it is very easy to enable the disabled button.

Learn more about jqueryATTRAndRemoveattrTwo functions are actually elements.DisabledAttribute.

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.