I'm working on Ajax and still learning to use it properly. I'm wondering why in one side of Ajax alert(); works but on the other side - no.
It's pretty basic code:
$('.naudoti_papildus_visiems').click(function() {
var n;
$.post('/ajax/naudoti_papildus_visiems.php', { status : 1, fermos_id : '<?php echo $id_kurat; ?>', gyvulio_tipas : '<?php echo $type_zagon; ?>' },
function(data) {
var typeclick = data.typeclick,
typeu = data.typeu,
stil = data.stil,
stildell = data.stildell;
$.noty.closeAll();
if (n) {
n.setText('<b>' + data.message + '</b>');
n.setType(typeu);
} else {
n = noty({
text: '<b>' + data.message + '</b>',
type: typeu,
dismissQueue: false,
layout: 'top',
theme: 'defaultTheme',
timeout: 3000,
});
}
}, 'json');
});
"naudoti_papildus_visiems.php" content:
<script>alert(9);</script>
I've tested one thing: using alert(); function inside an Ajax, it works:
$('.naudoti_papildus_visiems').click(function() {
var n;
$.post('/ajax/naudoti_papildus_visiems.php', { status : 1, fermos_id : '<?php echo $id_kurat; ?>', gyvulio_tipas : '<?php echo $type_zagon; ?>' },
function(data) {
var typeclick = data.typeclick,
typeu = data.typeu,
stil = data.stil,
stildell = data.stildell;
alert(9); // works
$.noty.closeAll();
if (n) {
n.setText('<b>' + data.message + '</b>');
n.setType(typeu);
} else {
n = noty({
text: '<b>' + data.message + '</b>',
type: typeu,
dismissQueue: false,
layout: 'top',
theme: 'defaultTheme',
timeout: 3000,
});
}
}, 'json');
});
Chrome console doesn't show any errors. Any help would be appreciated.
loelsonk:
still doesn't work. Am I doing something wrong?
$('.naudoti_papildus_visiems').click(function() {
var n;
$.ajax({
url: '/ajax/naudoti_papildus_visiems.php',
type: 'POST',
dataType : 'json',
data: { status : 1, fermos_id : '<?php echo $id_kurat; ?>', gyvulio_tipas : '<?php echo $type_zagon; ?>' },
success: function(data) {
var typeclick = data.typeclick,
typeu = data.typeu,
stil = data.stil,
stildell = data.stildell;
$.noty.closeAll();
if (n) {
n.setText('<b>' + data.message + '</b>');
n.setType(typeu);
} else {
n = noty({
text: '<b>' + data.message + '</b>',
type: typeu,
dismissQueue: false,
layout: 'top',
theme: 'defaultTheme',
timeout: 3000,
});
}
$('#data').html(data);
}
});
});