I’m trying to add a simple line in a div, but append doesn’t work, alert and set values dont work
<script>
$('#salvaprod').on('click', function() {
$.ajax({
type: 'post',
url: 'lcompras_add_sql.php',
datatype: 'html',
data: {
qtdp: $('#qtdp').val(),
produtop: $('#produtop').val(),
}
}).done(function(data) {
requisitarPagina('') //it insert on database
})
})
function requisitarPagina(url) {
let ajax = new XMLHttpRequest();
ajax.open('POST', url)
parent.jQuery.fancybox.close();
ajax.onreadystatechange = () => {
if(ajax.readyState == 4 && ajax.status == 200) {
// add no extrato
alert("ttt"); //Alert doesnt work
html='<div class="cx_item"><i class="fa-regular fa-circle-right"></i> '+$('#qtdp').val()+'x '+$('#produtop').val()+'</div>';
$("#listac").append(html);//append doesnt work
document.getElementById('qtdp').value = '1'; //Values not reseted
document.getElementById('produtop').value = '';//Values not reseted
$.wnoty({
// 'success', 'info', 'error', 'warning'
type:'success',
message:'Produto adicionado com sucesso',
autohideDelay: 5000,// 5 seconds
// "top-left", "bottom-left", "top-right", "bottom-right"
position:'top-right',
});//wnoty works fine
console.log(html) //does not log
}
if(ajax.readyState == 4 && ajax.status == 404) {
//document.getElementById('resultado').innerHTML = '.. tente novamente mais tarde :s ..'
// document.getElementById('modal').style.visibility = 'hidden'
$.wnoty({
// 'success', 'info', 'error', 'warning'
type:'error',
message:'Produto não incluido, tente novamente',
autohideDelay: 7000,// 5 seconds
// "top-left", "bottom-left", "top-right", "bottom-right"
position:'top-right',
});
}
}
ajax.send()
console.log(ajax)
}
</script>
The data is inserted on DB, I get wnoty notification but html doesn’t append to listac
div.
Tried lots of different syntaxes, tried even alert
, just before append
, but that didn’t work either.
tried change sintaxes, tried just a simple alert, not working…
New contributor
Fernando Silva Florim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4