【问题标题】:Jquery Ajax call Web Service API2Jquery Ajax 调用 Web Service API2
【发布时间】:2014-05-27 19:18:52
【问题描述】:

我正在使用客户端 javascript 调用 Web api 服务上的授权控制器。

            $.ajax({
                url: 'http://10.0.1.18/WebAPISampleDB/api/values',
                type: 'GET',
                success: function (result) {
                    alert(result);
                },
                error: function (result) {
                    alert(result);
                }

            });

由于我尚未进行身份验证,我应该会收到 401 未经授权的消息。我看到这是一个未经授权使用 Firebug 的 401,但是当我尝试提醒结果时,它有一个空的 responseText。

使用 firebug 并检查响应标头,它看起来像 Content-Type = application/json;字符集=utf-8。并且 401 消息响应看起来是在 html 中。

所以从我收集的信息来看,因为我的返回类型是 json 并获取 html,它不知道该怎么做。

有没有办法从我的 ajax 调用返回中获取 401 未经授权的消息?

【问题讨论】:

    标签: jquery asp.net-web-api2


    【解决方案1】:

    试试这个:

    error: function(jqXHR, textStatus, errorThrown) {
       alert(jqXHR.status);
       alert(textStatus);
       alert(errorThrown);
    }
    

    【讨论】:

    • jqXHR.status 为 0,textStatus 为“error”,errorThrown 为空
    猜你喜欢
    • 2015-07-10
    • 1970-01-01
    • 2018-01-11
    • 2023-03-31
    • 1970-01-01
    • 2013-11-12
    • 2014-07-31
    • 2011-06-17
    相关资源
    最近更新 更多