gpt4 book ai didi

ajax - Bonsai Elasticsearch附加组件:401未经授权的错误

转载 作者:行者123 更新时间:2023-12-03 01:45:00 24 4
gpt4 key购买 nike

为了部署使用Elasticsearch的firebase应用程序,我正在使用Heroku Bonsai附加组件。

一切都准备就绪,问题是我在传递Ajax请求时遇到了未经授权的错误。完全相同的代码在本地(link)上运行正常,但在部署上却没有。

Ajax.jx

$(function() {
$('#message').keyup(function() {
var query = {
"query": {
"match": {
"song": {
"query": $("#message").val(),
"operator": "and"
}
}
}
};

$.ajax({
type: "POST",
url: "https://<username>:<password>@xxxwood-5671445.xx-xxxx-1.bonsaisearch.net/firebase/_search",
contentType: 'application/json',
crossDomain: true,
data: JSON.stringify(query),
success: searchSuccess,
dataType: 'json'
});

});

});

我为盆景URL使用了正确的用户名和密码,但无法正常工作。

控制台错误:
enter image description here

Chrome控制台错误: enter image description here

cURL可以正常运行:
[~]$ curl -XGET 'https://<username>:<password>@dogwood-5671445.xx-xxxx-1.bonsaisearch.net/firebase/_search?pretty' -H 'Content-Type: application/json' -d'
{"query": {"match": {"song": {"query": "i am in", "operator": "and"}}}}'

cURL result:


{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.4048493,
"hits" : [ {
"_index" : "firebase",
"_type" : "song",
"_id" : "0001",
"_score" : 1.4048493,
"_source" : {
"song" : "i am in california",
"song_name" : "hello",
"song_url" : "https://xxx.xx/xxxx"
}
} ]
}
}

问题:我缺少什么?

最佳答案

可能Ajax没有从URL传递凭据。通过HTTP header 附加auth,如下所示:How to use Basic Auth with jQuery and AJAX?

关于ajax - Bonsai Elasticsearch附加组件:401未经授权的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44734567/

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