Anonymous
Я не могу выполнять операции добавления к функции ajax
Сообщение
Anonymous » 01 июл 2024, 06:51
Я пытаюсь добавить простую строку в элемент div, но добавление не работает
Код: Выделить всё
$('#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('')
})
})
function requisitarPagina(url) {
let ajax = new XMLHttpRequest();
ajax.open('POST', url)
ajax.onreadystatechange = () => {0
if(ajax.readyState == 4 && ajax.status == 200) {
parent.jQuery.fancybox.close();
html='[i][/i] '+$('#qtdp').val()+'x '+$('#produtop').val()+'';
$("#listac").append(html);
$('#qtdp').val()='1';
$('#produtop').val()='';
$.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',
});
alert (html);
}
if(ajax.readyState == 4 && ajax.status == 404) {
//document.getElementById('resultado').innerHTML = '.. tente novamente mais tarde :s ..'
// document.getElementById('modal').style.visibility = 'hidden'
parent.jQuery.fancybox.close();
$.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)
}
Данные вставляются в БД, я получаю пустое уведомление, но html не добавляется в список listac div.
Пробывал много разные синтаксисы, пробовал даже alert, непосредственно перед добавлением, но это тоже не сработало.
Подробнее здесь:
https://stackoverflow.com/questions/786 ... x-function
1719805889
Anonymous
Я пытаюсь добавить простую строку в элемент div, но добавление не работает [code] $('#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('') }) }) function requisitarPagina(url) { let ajax = new XMLHttpRequest(); ajax.open('POST', url) ajax.onreadystatechange = () => {0 if(ajax.readyState == 4 && ajax.status == 200) { parent.jQuery.fancybox.close(); html='[i][/i] '+$('#qtdp').val()+'x '+$('#produtop').val()+''; $("#listac").append(html); $('#qtdp').val()='1'; $('#produtop').val()=''; $.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', }); alert (html); } if(ajax.readyState == 4 && ajax.status == 404) { //document.getElementById('resultado').innerHTML = '.. tente novamente mais tarde :s ..' // document.getElementById('modal').style.visibility = 'hidden' parent.jQuery.fancybox.close(); $.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) } [/code] Данные вставляются в БД, я получаю пустое уведомление, но html не добавляется в список listac div. Пробывал много разные синтаксисы, пробовал даже alert, непосредственно перед добавлением, но это тоже не сработало. Подробнее здесь: [url]https://stackoverflow.com/questions/78690233/i-cannot-make-append-works-on-an-ajax-function[/url]