JSONP不点火beforeSend? [英] jsonp is not firing beforeSend?

查看:309
本文介绍了JSONP不点火beforeSend?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个项目叫使用$阿贾克斯由于数据类型设置为JSONP不同域中的Web服务。

I am working on a project to call a webservice from different domain using $.ajax with dataType set to jsonp.

    $.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是不是被解雇

The problem is I have a ...loading animation which I want to display while the web service request is being processed. I tried using "beforeSend:" to show the loading animation but it seems like "beforeSend" is not getting fired.

动画正常工作时,该应用程序是在同一个域(使用JSONP),但是当我移动应用程序到不同的服务器上,一切工作除了beforeSend是没有得到调用。因此,用户将不能够看到加载动画

The animation works fine when the app is on the same domain (using jsonp) but when I move the app into a different server, everything works except "beforeSend" is not getting called. So users will not be able to see the loading animation.

有什么解决方法吗?

推荐答案

跨域JSONP请求不使用XMLHTT prequest,因此事件流是不同的。

Cross-domain JSONP requests do not use XMLHTTPRequest, so the event flow is different.

您可以简单地调用$阿贾克斯后立即显示您的加载动画。

You can simply show your loading animation right after calling $.ajax.

这篇关于JSONP不点火beforeSend?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆