gpt4 book ai didi

javascript - Jquery 1.10.2 跨域请求

转载 作者:行者123 更新时间:2023-11-28 23:30:07 25 4
gpt4 key购买 nike

我提出以下要求:

function doPoolPartyGetChildrenAjaxRequest(parent) {

return $.ajax({

url: "http://127.0.0.1:8086/PoolParty/api/thesaurus/1DCE2E49-7DD8-0001-524C-1A1B14A0141A/childconcepts",

data: {language: "en", parent: parent, properties: "skos:narrower"},

username: 'xxxx',
password: 'xxxx',

dataType: 'json',

crossDomain: true,


beforeSend: function (req) {
req.setRequestHeader('Authorization', 'Basic ' + btoa('superadmin:poolparty'));
},

xhrFields: {
withCredentials: true
},

error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
},

success: function (data) {

for (var i = 0; i < data.length; i++) {
data[i].title = data[i].prefLabel

if (!(data[i].narrowers === undefined)) {
data[i].lazy = true
}
}

data.sort(function(a, b) {

if (a.prefLabel.toLowerCase() == b.prefLabel.toLowerCase())
return 0;
if (a.prefLabel.toLowerCase() > b.prefLabel.toLowerCase())
return 1;
else
return -1

});

}
})

我需要做什么才能让它工作,这是我得到的错误:

OPTIONS http://127.0.0.1:8086/PoolParty/api/thesaurus/1DCE2E49-7DD8-0001-524C-1A1B…Fthesaurus.iadb.org%2Fpublicthesauri%2FIdBTopics&properties=skos%3Anarrower 401 (Unauthorized) m.ajaxTransport.send
m.extend.ajax doPoolPartyGetChildrenAjaxRequest setPoolPartyTreeBroswer
(anonymous function)
m.Callbacks.j m.Callbacks.k.fireWith
m.extend.ready
J XMLHttpRequest cannot load http://127.0.0.1:8086/PoolParty/api/thesaurus/1DCE2E49-7DD8-0001-524C-1A1B14A0141A/childconcepts?language=en&parent=http%3A%2F%2Fthesaurus.iadb.org%2Fpublicthesauri%2FIdBTopics&properties=skos%3Anarrower. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 401. error

我不太了解这个错误。我如何查看我的代码是否向服务器发送了正确的 header ?我怎样才能看到服务器的响应。

我的 Tomcat 7 配置如下:

<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>10</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

我不知道我还需要做什么。请任何人都可以指导我。

我怎样才能检查出来,什么是发送接收。 jquery 1.10.2 有什么特别之处吗?

是不是Tomcat 7的corsfilter有问题?

我过去曾使用 tomcat6 工作过。从那以后,我换成了 tomcat 7,但它根本不起作用。

最佳答案

您是否在禁用 CORS 的情况下运行 Chrome?尝试从命令行运行:

google-chrome --disable-web-security

有关如何禁用网络安全的更多信息,请查看 here

关于javascript - Jquery 1.10.2 跨域请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31575148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com