JSFiddle - React, Tailwind, and code Playground
by borcagos
HTML
<hr> login
<input type="text" id="login" value='[email protected]'> password
<input type="password" id="pass">
<input type="button" id="checkAuth" value='connect'>
<hr>
<div id="main">
JavaScript
var token = '';
function checkAuth() {
let login = document.getElementById('login').value
let pass = document.getElementById('pass').value
// alert(login+'='+pass);
var res_div = document.getElementById('main')
var url = "http://127.0.0.1:8081/https://cropio.com/api/v3/sign_in"
$.ajax({
type: 'POST',
url: url,
async: false,
contentType: 'application/json',
data: {
'user_login': {
'email': '[email protected]',
'password': 'YwL3JKCk'
}
},
success: function(data) {
res_div.innerHTML = 'SOOO GOOD' + JSON.stringify(data, null, '<p>');
},
error: function(oError) {
res_div.innerHTML = 'IT IS FAIL<hr>' + JSON.stringify(oError, null, '<p>');
}
});
}
/*
var request = new XMLHttpRequest();
request.open('POST', 'http://127.0.0.1:8081/https://cropio.com/api/v3/sign_in');
//request.open('POST', 'https://cropio.com/api/v3/sign_in');
request.setRequestHeader('Content-Type', 'application/json');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
var body = {
'user_login': {
'email': '[email protected]',
'password': 'YwL3JKCk'
}
};
request.send(JSON.stringify(body));
*/
document.getElementById('checkAuth').onclick = checkAuth;