Why doesn't HourGlass work with synchronous AJAX request in Google Chrome?

I execute a function where first I make a cursor to wait for the state (hourglass) and then I send a synchronous AJAX request. After receiving the response, I make the cursor the default state.

The actual code is ..

// checks smtp parameters function TestSettings () {var buttonparams = new Object ();

buttonparams.IsCommandButton = true; buttonparams.ButtonId = "testsettings"; buttonparams.ButtonText = "Sending Test Mail..."; buttonparams.ButtonOrigText = "Test Settings"; if(buttonparams.IsCommandButton == true) HandleButtonStatus(true, buttonparams); var request = function() { var ret = SendForm(buttonparams); alert(ret); } window.setTimeout(request, 0); 

}

function SendForm (pButtonParams) {var http; var formdata;

 http = yXMLHttpRequest(); http.open("POST", "./", false); http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); http.setRequestHeader("Req-Type", "ajax"); formdata = xEncodePair("_object", "PrefMgr")+ "&"; formdata += xEncodePair("_action", "SmtpTest")+ "&"; formdata += GetEncodedFormData(); http.send(formdata); if(http.status == 200) { if(pButtonParams.IsCommandButton == true) HandleButtonStatus(false, pButtonParams); return (http.responseText); } else { return ("Error " + http.status + ": " + http.statusText); } 

}

Function HandleButtonStatus (pIsButtonStatusChange, pButtonParams) {var button = yById (pButtonParams.ButtonId);

 if(pIsButtonStatusChange) { document.body.style.cursor = "wait"; button.value = pButtonParams.ButtonText; button.disabled = true; } else { document.body.style.cursor = "default"; button.disabled = false; button.value = pButtonParams.ButtonOrigText; } 

}

+1
source share
1 answer

Try to assign:

 var st = document.body.style; 

and then refer to st in both functions. This can be a volume problem in the AJAX callback function.

EDIT: Use the callback function to restore the shape of the cursor. Remember to do the same if the AJAX call fails.

+1
source

Source: https://habr.com/ru/post/900960/


All Articles