Dar de alta sistmeas en ajax popup
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form method="POST" action=".">
|
||||
<form method="POST" action="." id="cliente-form">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label for="{{form.RFC.name}}"><strong> {{form.RFC.label|capfirst}} </strong></label>
|
||||
@@ -34,7 +34,51 @@
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
|
||||
|
||||
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();
|
||||
}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')
|
||||
}
|
||||
})
|
||||
|
||||
window.addEventListener("load", (event)=>{
|
||||
if(!id_Activo.checked){
|
||||
id_fecha_baja.setAttribute('required','')
|
||||
|
||||
Reference in New Issue
Block a user