[英]Why HourGlass not working with synchronous AJAX request in Google Chrome?
I am executing a function where first I am making cursor to wait state(hourglass) and then I am sending a synchrounous AJAX request .After getting the response I am making cursor to default state. 我正在执行一个函数,首先使光标处于等待状态(沙漏),然后发送同步的AJAX请求。获得响应后,我使光标处于默认状态。
The Actual Code is this.. 实际的代码是这个。
// tests the smtp settings function TestSettings() { var buttonparams= new Object(); //测试smtp设置功能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; 函数SendForm(pButtonParams){var http; var formdata;
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); 函数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;
}
} }
Try to assign: 尝试分配:
var st = document.body.style;
and then refer to st
in both functions. 然后在两个函数中都引用
st
。 This could be a scope issue in AJAX callback function. 这可能是AJAX回调函数中的作用域问题。
EDIT: Use callback function to restore cursor shape. 编辑:使用回调函数恢复光标形状。 Don't forget to do the same in case AJAX call fails.
如果AJAX调用失败,请不要忘记这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.