changes for sistemas

This commit is contained in:
fjrodriguez
2023-03-09 09:40:17 -06:00
parent c84ef13d33
commit 5b5e79f430
7 changed files with 108 additions and 89 deletions

View File

@@ -37,42 +37,33 @@
document.addEventListener("DOMContentLoaded", ()=>{
if(window.name ==='popupWin')
{
console.log('popupWin')
{
document.querySelector("#cliente-form").addEventListener('submit',(event)=>{
event.preventDefault();
let form= event.target;
let url = `{% url 'add_cliente' %}`;
let data = new FormData(form);
let xhr = new XMLHttpRequest();
xhr.open('POST',url);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onreadystatechange = ()=>{
if(xhr.readyState===XMLHttpRequest.DONE){
if(xhr.status===200){
let response = JSON.parse(xhr.responseText);
window.opener.postMessage({data:response, windowName:'clientWindow'},window.location.origin);
window.close();
if(response.errors){
alert(response.errors)
}else{
window.opener.postMessage({data:response, windowName:'clientWindow'},window.location.origin);
window.close();
}
}else{
console.error('Request error ',xhr.statusText);
}
}
};
xhr.send(data);
/*
fetch(url,{
method:'POST',
body:data
})
.then(response=>response.json())
.then(response=>{
window.opener.postMessage({data:response, windowName:'clientWindow'},window.location.origin);
window.close();
})
.catch(error => console.log(error));
*/
});
}else{
console.log('not popupWin')