0
Good morning everyone. Would it be possible to use javascript when entering a page, automatically create a new column in a table in the database ? Something like this: The user enters the page and already receives a call number and if he leaves the page without completing would make a rollback erasing this record not started in the database.
That’s the page I got:
<body onload="salvaBancoAjax()">
<!-- main -->
<main class="container">
<!-- messages -->
//aqui deveria entrar o id registrado
<center><h1><i class="fas fa-balance-scale"></h1></i><br><br><h2>
Atendimento numero <input class="o-form__data" name="id" type="text">
</h2></center>
</div>
</div>
</main>
<!-- ./main -->
<br>
<br>
<!-- Bootstrap core JavaScript
================================================== -->
//este é o ajax
<script type="text/javascript">
function salvaBancoAjax() {
let url = 'php/adiciona-atendimento.php' + '/json';
let xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status = 200)
preencheCampos(JSON.parse(xhr.responseText));
}
}
xhr.send();
}
function preencheCampos(json) {
document.querySelector('input[name=id]').value = json.id;
}
</script>
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
<script src="assets/bootstrap-4.0.0/assets/js/vendor/popper.min.js"></script>
<script src="assets/bootstrap-4.0.0/dist/js/bootstrap.min.js"></script>
<script src="assets/bootstrap-4.0.0/assets/js/vendor/holder.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="https://igorescobar.github.io/jQuery-Mask-Plugin/js/jquery.mask.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
yes, just put the Documenready javascript code to run when the page is loaded
– Ricardo Pontual
ola Ricardo edited the post showing that what I need is automatically the insertion of the data (id) will be carried out and the information will be without the page reload. But I’m not able to run the script. thanks
– Sergio Guerjik