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

@@ -15,46 +15,41 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('#sistema-form').addEventListener('submit', function(event) {
event.preventDefault();
var form = event.target;
var url = form.getAttribute('action');
var data = new FormData(form);
fetch(url, {
method: 'POST',
body: data
})
.then(response => response.json())
.then(response => {
window.opener.postMessage({data:response, windowName:'sistemaWindow'}, window.location.origin);
window.close();
})
.catch(error => console.log(error));
});
});
/*
<!--script src="https://code.jquery.com/jquery-3.6.0.min.js">
$(function() {
$('#sistema-form').submit(function(event) {
document.querySelector('#sistema-form').addEventListener('submit', function(event) {
event.preventDefault();
var form = $(this);
var url = form.attr('action');
var data = form.serialize();
$.ajax({
url: url,
data: data,
type: 'post',
dataType: 'json',
success: function(response) {
window.opener.postMessage(response, '*');
window.close();
},
error: function(xhr, status, error) {
console.log(xhr.responseText);
var form = event.target;
var url = form.getAttribute('action');
var data = new FormData(form);
fetch(url, {
method: 'POST',
body: data
})
.then(response => {
if(response.ok){
return response.json();
}else{
throw new Error('Network response was not ok');
}
})
.then(response => {
if(response.errors) {
alert(response.errors)
id_nombre_sistema.value=''
}else{
window.opener.postMessage({data: response, windowName: 'sistemaWindow'}, window.location.origin);
window.close();
}
})
.catch(error => {
if(error.response){
alert('Error System AS_000')
}else{
alert('Error System AS_001')
}
});
});
});*/
});
</script>
{% endblock scripts %}