我有以下设置,其中Javascript发送一个AJAX请求并且它被执行得很好。问题是AJAX提交没有得到服务器的回复以显示在UI中。 console.log(msg)
可以正常工作,但其余的都没有表现。如何确保在Javascript中收到PHP的每个输出?
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');
编辑: XHR正文有数据
答案 0 :(得分:1)
你没有从你的帖子请求中返回json删除json属性
$.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);
});