我正在尝试通过以下代码调用 API。但是我的浏览器给出了同样的错误并且没有从服务器得到响应。
我的 API 工作正常,我已经通过邮递员进行了测试。我不知道我哪里出错了
我也试过放一些标题内容类型
application/json , application/x-javascript , application/javascript , text/json
function send(text) {
$.ajax({
url: 'http://localhost:5005/conversations/default/respond',
type: 'POST',
dataType:'jsonp',
headers: {
'Content-Type': 'application/javascript'
},
data: //JSON.stringify({
{
"q": text
},//),
success: function (data, textStatus, xhr) {
console.log(data);
if (Object.keys(data).length !== 0) {
for (i = 0; i < Object.keys(data[0]).length; i++) {
if (Object.keys(data[0])[i] == "buttons") { //check if buttons(suggestions) are present.
addSuggestion(data[0]["buttons"])
}
}
}
setBotResponse(data);
},
error: function (xhr, textStatus, errorThrown) {
console.log('Error in Operation');
setBotResponse('error'); …Run Code Online (Sandbox Code Playgroud)