So I'm trying to recreate an ajax function in normal JS, but i don't know how to do it. The function activates an ifttt function, and i want to use normal JS instead of jQuery. Note, this is different from other questions is because this involves "jsonp". I have looked up these questions but i don't understand them fully or don't apply to my code. When i call the ajax function it does something with my data that i just cant seem to achieve with normal JS. Here is the ajax:
var key = "thisisanexamplekey";
var message_name = "send_message";
var url = "https://maker.ifttt.com/trigger/" + message_name + "/with/key/" + key;
$.ajax({
url: url,
data: {value1: message,
value2: email},
dataType: "jsonp",
complete: function(jqXHR, textStatus) {
console.log("Message Sent");
}
});
And here is my JS function that doesn't work:
var key = "thisisanexamplekey";
var message_name = "send_message";
var data = 'value1=' + encodeURIComponent(message) + '&value2=' + encodeURIComponent(localStorage.getItem("AdminsEmail"));
console.log(data);
var url = "https://maker.ifttt.com/trigger/" + message_name + "/with/key/" + key;
console.log(message + email);
var script = document.createElement("script");
script.setAttribute("src",url + "?callback="+data);
document.body.appendChild(script);
I get the feeling the JS function is pretty off, can anyone help me?