YumYumYum YumYumYum - 18 days ago 4
PHP Question

Javascript is submitting a simple request but not getting proper feedback

I have the following setup where Javascript sends an AJAX request and it gets executed fine. The problem is that the AJAX submission is not getting the reply from server to display in the UI.

console.log(msg)
works but all the rest does not behave at all. How can I make sure every single output from PHP is received in Javascript?

ajax.php:

<?php
$cmd = $_POST['command'];
echo shell_exec("/usr/local/software/bin/cli -x '{$cmd}'");
?>


javascript.php:

$.post('ajax.php', {
action: 'FEEDBACK-PLEASE?????',
command: 'show status'
}, function(msg) {
console.log(msg); // shows data arrived
// following does not show the msg at all
$('#terminal_output').html(msg);
alert('HELLO!!!!!! HELLO!! where is my feedback!! why you no alert???');
}, 'json');


EDIT: XHR body has data

enter image description here

Answer

you are not returning json from your post request remove the json property

$.post('ajax.php', {
    action: 'FEEDBACK-PLEASE?????',
    command: 'show status'
}, function(msg) {
    console.log(msg); // shows data arrived
    // following does not show the msg at all
    $('#terminal_output').html(msg); 
});