0
I have a problem, that I researched and thought how to do, but I could not solve. I have a select
on the page that needs to be populated after a condition is met. And after that, it needs to query the data relating to the option chosen in select. Suppose this select is to fill in the user name, and after it is filled in, a query should be made in the database with the data relating to that user. And that’s where my problem is, although I can fill in the select and bring the data related to the chosen user, every time the page starts, the script runs again and all the time. It’s kind of like a query loop that I can’t stop. How can I make it just a query and after that, he interrupts so that the query is not made again?
It’s more of a logic problem than a syntax problem, which is why I reduced the code itself.
<script>
$(document).ready(function () {
if (condicao) {
$.ajax({
// execução do ajax, aqui preencho o select
});
// aqui está o problema, ao preencher o select, é para submeter o form. Porém isso tem causado loop na consulta
}
})
</script>
<form method="post">
<select class='form-control' id='opcoes'>
</select>
</form>
What returns in ajax?
– Matheus
that ajax, returns data in json format, with which I fill the select. After that, I need to submit the form, and that’s my problem, I don’t know where I can put this form to consult without it loop with it
– DiChrist
everything happens the way I want, except this loop
– DiChrist
At first you can solve it by creating a flag (true/false) in the session, where when the ajax operation is performed, in the controller you change the flag to false. In JS, you can recover a session variable using "${flag}".
– Matheus
well thought out, a session variable in javascript itself...
– DiChrist