Hi
I am playing with Javascript and successfully wrote functions to list all tokens and request a new token, but I have problems with deleting a token. Often i not get any response, sometimes token i want to delete is gone from the list, and often the token is still valid after when i refresh token list.
I have also tested it with Hurl.it and very often i get “Request timed out”.
Here is my code: I fill my credentials and token i want to delete in a form:
function removeToken() {
var xml = new XMLHttpRequest();
//read in username/password from form
var username = document.getElementById("myForm").elements[0].value;
var password = document.getElementById('myForm').elements[1].value;
var token = document.getElementById('Form2').elements[0].value;
var url = "https://api.spark.io/v1/access_tokens/";
xml.open("DELETE", url + token, true);
xml.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password))
xml.onreadystatechange = function (aEvt) {
if (xml.readyState == 4) {
}
};
xml.send()
alert(xml.responseText);
listTokens();