It seems like there are others facing similar issues without finding a solution. Here is the situation:
The user clicks a button to reveal a hidden div that contains a textarea for making comments:
//revealing the textarea-containing div
$('#postTypeContainer').css({ 'display': 'block' });
Then, the user inputs a comment, submits it, hides the div, and sends data to the server:
$("#loading").ajaxStart(function () {
$(this).show(); //displays a spinner
}).ajaxComplete(function () {
$(this).hide(); //hides the spinner
//hiding the previously opened div
$('#postTypeContainer').fadeOut('fast');
});
//sends data
$.ajax({
type: "POST",
url: rootUri + "main.aspx/StartNewThread",
data: jsonText,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (markUp) {
//doing stuff
}
});
All of this functions correctly.
Next, the user reopens the div by clicking on it, which works as expected
//revealing the textarea-containing div
$('#postTypeContainer').css({ 'display': 'block' });
Then, the user enters some data, such as @abc to tag another user, and using jQuery on 'keyup', the following happens:
//ajax call to find users matching the @abc
$.ajax({
type: "POST",
url: rootUri + "main.aspx/GetMatch",
data: jsonText,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//handling the response data
}
});
After this ajax call completes, the previously opened div suddenly closes, almost as if the DOM is reverting back to its initial state before the ajax call. This abrupt closure of the div while trying to interact with the textarea can be frustrating for the user. The only workaround seems to be refreshing the page, but that defeats the purpose of using ajax. Any insights on what might be causing this issue would be greatly appreciated. One unsuccessful attempt I made was checking the div's state within the keyup function responsible for the ajax tagging call and trying to keep it open at the end of the call, but that did not work as intended. Any assistance would be welcomed.