Javascript 带有Promise对象的Ajax正在阻止UI元素
我正在创建一个登录表单,并且为我的应用程序在下面创建了一个服务调用对象Javascript 带有Promise对象的Ajax正在阻止UI元素,javascript,jquery,angularjs,ajax,Javascript,Jquery,Angularjs,Ajax,我正在创建一个登录表单,并且为我的应用程序在下面创建了一个服务调用对象 Util.postServiceCall = function(url, formData, handlerDone, handlerAlways, handlerFail, context, preventLoader) { handlerDone = typeof handlerDone === 'function' ? handlerDone : function() {}; handlerAlways
Util.postServiceCall = function(url, formData, handlerDone, handlerAlways, handlerFail, context, preventLoader) {
handlerDone = typeof handlerDone === 'function' ? handlerDone : function() {};
handlerAlways = typeof handlerAlways === 'function' ? handlerAlways : function() {};
handlerFail = typeof handlerFail === 'function' ? handlerFail : function() {};
var hostname = Util.sStorage('get', 'hostname');
if (hostname && hostname !== 'undefined' && hostname !== 'null') {
REST_ROOT_URL = window.location.protocol + '//' + JSON.parse(hostname) + Util.getContextPath() + '/rest';
}
var promise = $.ajax({
cache: false,
type: 'POST',
dataType: 'json',
contentType: 'application/json',
crossDomain: true,
url: REST_ROOT_URL + url,
data: JSON.stringify(formData)
})
.done(function(data, textStatus, jqXHR) {})
.always(function(data, textStatus, jqXHR) {})
.fail(function(data, textStatus, jqXHR) {});
return promise;
};
当我需要调用任何服务时,我调用这个方法
Util.postServiceCall('/test/login',{},function(data){
});
但是当我遇到未经授权的错误时,页面中的表单元素被阻止,无法在输入框中键入任何内容,也无法清除这些内容
如果我像这样直接使用AJAX调用
$.ajax({
cache: false,
type: 'POST',
dataType: 'json',
contentType: 'application/json',
crossDomain: true,
url: REST_ROOT_URL + url,
data: JSON.stringify(formData)
})
.done(function(data, textStatus, jqXHR) {})
.always(function(data, textStatus, jqXHR) {})
.fail(function(data, textStatus, jqXHR) {});
那么UI元素就不会被阻塞
我很奇怪为什么这种行为是不同的。在每次调用
Util.postServiceCall()
时都定义了REST\u ROOT\u URL
?您的Util.sStorage
或Util.getContextPath()
与此有关吗?不,所有人都有自己的值。。REST\u ROOT\u URL是Util.postServiceCall()中的全局常量重新分配