<div class="asd"> <img src....> </div>
.asd img{
position: absolute;
top: 100vh;
left: 5%;
}
function sendForm(elem) {
elem.addEventListener('submit', function(e){
e.preventDefault();
elem.appendChild(statusMsg);
let formData = new FormData(elem);
function postData(data) {
return new Promise(function(resolve, reject){
let request = new XMLHttpRequest();
request.open('POST', 'smail.php');
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
request.onreadystatechange = function () {
if(request<4) {
resolve();
}else if(request.readyState == 4) {
if(request.status == 200 && request.status < 300){
resolve();
}else{
reject();
}
}
};
let obj = {};
formData.forEach(function(value, key){
obj[key] = value;
});
let data = JSON.stringify(obj);
request.send(data);
console.log(data);
});
}
function clearInput(){
for(let i = 0; i < input.lenght; i++) {
input[i].value = '';
}
}
postData(formData).then(()=> statusMsg.innerHTML = message.loading)
.then(()=>statusMsg.innerHTML = message.succes)
.catch(()=>statusMsg.innerHTML = message.failure)
.then(clearInput);
});
}
sendForm(formst);
function sendForm(elem) {
elem.addEventListener('submit', function(e){
e.preventDefault();
elem.appendChild(statusMsg);
let formData = new FormData(elem);
function postData(data) {
return new Promise(function(resolve, reject){
let request = new XMLHttpRequest();
request.open('POST', 'smail.php');
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.onreadystatechange = function () {
if(request<4) {
resolve();
}else if(request.readyState == 4) {
if(request.status == 200 && request.status < 300){
resolve();
}else{
reject();
console.log(request.status);
}
}
};
let obj = {};
formData.forEach(function(key, value){
obj[value] = key;
});
let data = JSON.stringify(obj);
request.send(data);
console.log(obj);
});
}
function clearInput(){
for(let i = 0; i < input.lenght; i++) {
input[i].value = '';
}
}
postData(formData).then(()=> statusMsg.innerHTML = message.loading)
.then(()=>statusMsg.innerHTML = message.succes)
.catch(()=>statusMsg.innerHTML = message.failure)
.then(clearInput);
});
}
sendForm(formst);