
When there is an AJAX call going through, you should disable the control that makes the AJAX call and also the controls whose contents will be updated by the AJAX call. In this tutorial, I will show how to disable the controls during AJAX calls.
Creating the Mock-up AJAX feature
Consider a situation when a user logs in to a website. He/she enters the username and password and then clicks the Submit button. The HTML code of the control is given below.
<div id="content">
<h3><b><u>Login</u></b></h3>
<table>
<tr>
<td>Username:
</td>
<td>
<input type="text" id="userNameTextBox" />
</td>
</tr>
<tr>
<td>Password:
</td>
<td>
<input type="text" id="passwordTextBox" />
</td>
</tr>
<tr>
<td colspan="3">
<input type="submit" id="submitButton" value="Login" />
</td>
</tr>
</table>
<img id="loadingImg" src="loading.gif" />
<div id="messageDiv"></div>
</div>
I have a “content” div which contains a “table”. The “table” contains “Username” & “Password” input controls along with a “submitButton”.
After the table, there is an “img” control that will show the loading image during AJAX call. I have also kept a “messageDiv” that will show the message when a user gets logged in to the website.
Note
My aim here is to disable the “username” & “password” input controls and also, the button control when AJAX call is made. I will also show the loading image over the center of the “Content” div during AJAX calls.
Add the CSS to the page
The CSS which you have to add to this page is mentioned below.
#content {
position: relative;
border: dashed 2px #CCC;
}
#content #loadingImg {
display: none;
position: absolute;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#content table {
margin: auto;
}
#content #messageDiv {
text-align: center;
}
Note
To show the image at the center of “content” div, first, set the position of the “content” div to "relative". Then, for the image, set its position to "absolute", margin to "auto", and “top,left,right & bottom” properties to 0.
Initially, the image will remain hidden but when AJAX call starts, it will be shown. Similarly, on completion of the AJAX call, the image will again be hidden.


Tridip BhattacharjeePosted Nov 8, 2017, 4:18 AM
Every control in table will be disabled if we disable table by jquery. say we have button, textbox, link etc so if we disable table then all controls inside table will be disabled ?