Dar de alta sistmeas en ajax popup
This commit is contained in:
60
Templates/Sistemas/Xclientes/sistema_create_form.html
Normal file
60
Templates/Sistemas/Xclientes/sistema_create_form.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<!-- sistema_create_form.html -->
|
||||
|
||||
|
||||
{% block content %}
|
||||
<h1>Create a new Sistema</h1>
|
||||
<form id="sistema-form" method="post" action="{% url 'create_sistemas_form' %}">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
|
||||
|
||||
<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) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
});*/
|
||||
</script>
|
||||
{% endblock scripts %}
|
||||
Reference in New Issue
Block a user