您好,我在天蓝色下创建了一个问答机器人。很好然后,我按照这些说明在邮递员中测试了该机器人
https://docs.microsoft.com/en-gb/azure/cognitive-services/QnAMaker/Quickstarts/get-answer-from-knowledge-base-using-url-tool?pivots=url-test-tool-postman
那也很好
我现在正尝试对其进行调整,以便可以在使用jquery的网页上使用它。我的代码如下:
function chatBot() {
var url = "https://myanda.azurewebsites.net/qnamaker/knowledgebases/asdf7-dd-dddd-9ddd782-ddddd/generateAnswer";
$.ajax({
url: url,
type: 'POST',
data: { "question": "this is my question" },
headers: {
"Authorization": "EndpointKey jdjdj-djkdaskj-d-dddd",
"Content-Type": "application/json"
},
dataType: 'json',
success: function (data) {
console.info(data);
}, error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + ":" + XMLHttpRequest + ":" + errorThrown);
}
});
}
但是我遇到以下错误
{"error":{"code":12,"message":"Parameter is null","target":null,"details":null,"innerError":null}}
有人可以帮忙吗?
谢谢
答案 0 :(得分:0)
好吧,如果其他任何人想要这样做,答案就很简单。似乎不希望问题和答案采用json格式,而只是一个字符串
function chatBot() {
var url = "https://myanda.azurewebsites.net/qnamaker/knowledgebases/asdf7-dd-dddd-9ddd782-ddddd/generateAnswer";
$.ajax({
url: url,
type: 'POST',
data: '{"question":"this is my question"}',
headers: {
"Authorization": "EndpointKey jdjdj-djkdaskj-d-dddd",
"Content-Type": "application/json"
},
success: function (data) {
console.info(data);
}, error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + ":" + XMLHttpRequest + ":" + errorThrown);
}
});
}
效果很好