0

我正在使用此处找到的jquery-jsonp库的 2.3.1.min 版本:https ://github.com/jaubourg/jquery-jsonp它按预期工作,即发生错误时会触发错误函数。但是,我似乎无法显示遇到的错误。我检查了 github 项目上的文档,但找不到答案。

这是一个限制吗?还是我没有调用正确的对象?

我的实现..

下面的 url 参数被设置为故意返回 404 页面。Chrome 开发工具显示 404 响应,但我似乎无法捕捉到该结果..

    <script type="text/javascript">
        $.jsonp({
                url: 'http://apps.mydomain.com/Service/NonExistant?&max=4&format=json',
                callbackParameter: "callback",
                error: function(xOptions, textStatus){ 
                    // this lines returns "error"
                    console.log(textStatus); 

                    // this returns the Object (but expanding it reveals no indication of error code / message)
                    console.log(xOptions);
                },
                success: function(json, textStatus) {
                    Populate(json); // this works fine
                }
            });
    </script>
4

1 回答 1

0

可悲的是,你不能。 Johnny Wey比我解释得好得多——但本质上,它依赖于“脚本”标签来获取 JSON 响应,而不是通过 javascript 执行的请求。

当 4xx 或 5xx Http Error Code is Present 时,您可以根据 Parsing JSONP Response in Javascript 将错误类型包装在JSONP 响应中,但这仍然无法帮助您解决 404 错误。

不幸的是,尽管 JSONP 错误处理实际上并不存在。IBM的“注意事项”特别提到“首先,JSONP 调用没有错误处理”。

于 2012-09-20T02:03:58.070 回答