【发布时间】:2015-06-30 06:33:09
【问题描述】:
我正在开发一个项目,以使用 $.ajax 并将 dataType 设置为 jsonp 从不同域调用 Web 服务。
$.ajax({
type: "GET",
url: testService.asmx,
async: true,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
beforeSend: function (XMLHttpRequest) {
alert('Before Send'); //Nothing happnes
},
success: function (response) {
alert('Success'); //this was fired
},
complete: function (XMLHttpRequest, textStatus) {
alert('After Send'); //this was fired
}
});
问题是我有一个...加载动画,我想在处理 Web 服务请求时显示它。我尝试使用“beforeSend:”来显示加载动画,但似乎“beforeSend”没有被触发。
当应用程序位于同一个域(使用 jsonp)时,动画效果很好,但是当我将应用程序移动到不同的服务器时,除了“beforeSend”之外的所有东西都没有被调用。所以用户将看不到加载动画。
有什么解决方法吗?
【问题讨论】: