kabeer
(Kabeer)
1
I am trying to create a UI using HTML and js. When i call a ajax call from js i am getting this error:
sanic.exceptions.MethodNotSupported: Method OPTIONS not allowed for URL /webhooks/rest/webhook
How can i solve this?
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
console.log('am here');
$.ajax({
url: "http://localhost:5005/webhooks/rest/webhook",
contentType:"application/json; charset=utf-8",
type:"POST",
data:
JSON.stringify({
"sender":"1234567890",
"message":'hi'
}),
success: function(result){
console.log('result',result);
}
});
})
</script>
</head>
endpoints.yml
action_endpoint:
url: "http://localhost:5055/webhook"
credentials.yml
rest:
rasa:
url: "http://localhost:5002/api" /// please explain the purpose of this url
I tried curl
command from the terminal like this:
curl -XPOST localhost:5005/webhooks/rest/webhook -d '{"sender":"Me","message":"hi?"}'
and it worked, also tried from an API client, that also worked. But from the JS its not working.
How can i solve this?
hey @kabeer, can you check this ajax call code:
kabeer
(Kabeer)
3
hey @JiteshGaikwad I tried your code, but still same error. Actually what’s the difference between our codes?
I thought might be the contentType
how did you start your rasa server, I mean the command for the rasa server?
did you tried using the below command:
rasa run -m models --enable-api --cors “*” --debug
kabeer
(Kabeer)
7
@JiteshGaikwad,
Here is the command rasa train && rasa run --enable-api --cors "*" --debug
kabeer
(Kabeer)
8
Yes, i tried. But no luck
Navjan
(Navod)
9
@kabeer Did you solve this problem? I am facing the same issue. Please guide me
stungkuling
(Prince Michael Fandino)
10
Hey, i’ve bumped into this same problem but i solved mine by using the “post” method in jquery.
from having this code:
$.ajax({
url: "http://localhost:5005/webhooks/rest/webhook",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ message: message, sender: user_id }),
success: function (botResponse, status) {
...
}
});
change it to something like this:
$.post("http://localhost:5005/webhooks/rest/webhook",
{ message: message, sender: user_id },
function (botResponse, status) {
...
}
);
I don’t know why this works but it works for me.