dimanche 26 mai 2019

Window.location.replace does not redirect me given url

Instead it redirects me to the url of main.js

function submitPOST(elementId, api, callback) {

    let input = document.getElementById(elementId).getElementsByTagName("input");

    let body = {};
    for (let i = 0; i < input.length; i++) {
        body[input[i].name] = input[i].value;
    }

    call('POST', api, body, callback);
}

function call(method, api,body, callback) {
    var xmlHttp = new XMLHttpRequest();

    xmlHttp.onload = function () {
        if (xmlHttp.status==200){
            callback(xmlHttp.response);
        }else{
            console.log(xmlHttp.response);
        }
    };
    xmlHttp.open(method, domainName+"/api/"+api, true); // true for asynchronous 
    xmlHttp.setRequestHeader("Content-Type", "application/json");
    xmlHttp.send(JSON.stringify(body));
}

function login(input){
    var response=JSON.parse(input);
    document.cookie="atoken="+response['data'];
    document.location.replace(domainName);
}




Aucun commentaire:

Enregistrer un commentaire