Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery AJAX调用导致错误状态403禁止_Javascript_Jquery_Ajax_Asp.net Mvc_Api - Fatal编程技术网

Javascript jQuery AJAX调用导致错误状态403禁止

Javascript jQuery AJAX调用导致错误状态403禁止,javascript,jquery,ajax,asp.net-mvc,api,Javascript,Jquery,Ajax,Asp.net Mvc,Api,我尝试对API进行一个简单的jquery ajax调用: 我的代码: $.ajax({ origin: "*", url: 'http://example/test', type: 'get', contentType: 'application/json; charset=utf-8', dataType: 'jsonp', crossDomain: true, beforeSend

我尝试对API进行一个简单的jquery ajax调用:

我的代码:

$.ajax({
        origin: "*",
        url: 'http://example/test',
        type: 'get',
        contentType: 'application/json; charset=utf-8',
        dataType: 'jsonp',
        crossDomain: true,
        beforeSend: function (xhr) {
                        xhr.setRequestHeader("API_KEY", 'xxx');
                        xhr.setRequestHeader("Authorization", 'xxx');
                    },
                    success: function (data) {
                    });
                },
                error: function () {
            }
        });
Api可以正确地使用授权和返回正确的数据,但当我从jQueryAjax调用它时,给出了错误403禁止

响应标题:

$.ajax({
        origin: "*",
        url: 'http://example/test',
        type: 'get',
        contentType: 'application/json; charset=utf-8',
        dataType: 'jsonp',
        crossDomain: true,
        beforeSend: function (xhr) {
                        xhr.setRequestHeader("API_KEY", 'xxx');
                        xhr.setRequestHeader("Authorization", 'xxx');
                    },
                    success: function (data) {
                    });
                },
                error: function () {
            }
        });
HTTP/1.1 403禁止 缓存控制:没有缓存 Pragma:没有缓存 内容类型:text/javascript;字符集=utf-8 过期:-1 服务器:Microsoft IIS/8.5 X-AspNet-Version:4.0.30319 X-Powered-By:ASP.NET 日期:2017年3月19日星期日格林尼治标准时间13:00:19 内容长度:127

请求头:

$.ajax({
        origin: "*",
        url: 'http://example/test',
        type: 'get',
        contentType: 'application/json; charset=utf-8',
        dataType: 'jsonp',
        crossDomain: true,
        beforeSend: function (xhr) {
                        xhr.setRequestHeader("API_KEY", 'xxx');
                        xhr.setRequestHeader("Authorization", 'xxx');
                    },
                    success: function (data) {
                    });
                },
                error: function () {
            }
        });
接受:/ 接受编码:gzip、deflate、sdch 接受语言:en-US,en;q=0.8 缓存控制:没有缓存 连接:保持活力 主持人:sp16应用程序:2525 Pragma:没有缓存 推荐人:


这里有一个语法错误:beforeSend:function(xhr){xhr.setRequestHeader(“API_KEY”,“xxx”;xhr.setRequestHeader(“Authorization”,“xxx”);},你能发布你得到的响应头吗?可能是语法错误的重复,只是由于错误我已经更新了@SimonaMii我不知道在哪里添加访问控制允许头@StanislavTalanov