My function myFunction
takes the username
and password
elements typed, and sends those values storing in a global variable to the next page.
My function tToken
authenticates this information and plays to the next page the valid Token for me to manipulate.
The problem is that I can not do or think of a way to play the login and password typed in the field for the next pages dynamically. Then I can do this but it works only on the LOGIN page, it displays the filled object only on the login page. When login is done and authenticated, after updating the page everything disappears, exactly because the values I want are stored in variables. How to do this, other than by variables?
var globalcredential = "/v1/credentials";
var globalauth = "/v1/auth";
var userlogin = new String();
var passwordlogin = new String();
function myFunction(){
var userElement = document.getElementsByName('username');
var passwordElement = document.getElementsByName('password');
userlogin = $(userElement).val().toString();
passwordlogin = $(passwordElement).val().toString();
};
function auth(){
var account = {
grant_type: "password",
login : userlogin,
senha : passwordlogin
};
var jsonAccount = JSON.stringify(account);
console.log(jsonAccount);
$.ajax({
type: "POST"
, method : "POST"
, url : globalauth
, contentType : "application/json"
, dataType : "json"
, data: jsonAccount
,success : function(data){
console.log("oi");
},beforeSend : function(request){
request.setRequestHeader('Content-Type', 'application/json');
},
}).done(function(response, status){
console.log(response,status);
}).fail(function(error){
console.log(error);
}).always(function(response, status){
});
}
var classname = document.getElementsByClassName("buttonlogin");
Array.from(classname).forEach(function(element) {
element.addEventListener('click', myFunction);
element.addEventListener('click', auth);
});