I am new to Javascript , currently writing up a script which sending some string as JSON to Mattermost incoming hook(Mattermost only accept JSON data) . I've tested it with curl , it works without any issues, the command is below :
curl -i -X POST -H 'Content-Type: application/json' -d '{"text": "Hello, this is some text\nThis is more text. :tada:"}'http://mattermost.test.nz/hooks/xxxxxxxxxxxxxxxxxxx
This is the script that I wrote, it's not sending the data to the endpoint for some reason, I've tried to figure it out myself but it's just not working . Please can anyone help..
var xmlhttp = new XMLHttpRequest();
var url = "http://mattermost.test.nz/hooks/xxxxxxxxxxxxxxxxxxx";
var data = {"test"};
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/json; charset=UTF-8");
xmlhttp.send(JSON.stringify(data));