我正在使用 ajax 发布到 php 页面(忽略发布的数据,这不重要)
当我使用以下命令在我的 linux 服务器上运行 php 页面时: php addHit.php 它正确地回显了远程服务器的主机名。然而这在 ajax 中不会发生,我得到的只是成功函数所在的空白警报。你可以在这里看到它的实际效果:http: //ec2-54-244-169-118.us-west-2.compute.amazonaws.com/bootstrap/jumbotron-narrow/index.php
<script>
$(function() {
$("form[name=addHit]").submit(function() {
alert("I am an alert box!");
var link = $("input[name=link]").val();
var comments = $("input[name=comments]").val();
var datastring = "link="+link+"&comments="+comments;
alert(datastring);
$.ajax({
type: "POST",
url: "/bootstrap/jumbotron-narrow/addHit.php",
data: datastring,
success: function(data, status, xhr) {
alert(data);
},
error: function(httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
alert("here");
return false;
});
});
</script>
我的 addHit.php 页面
$commands = "ssh -i adoekey.pem ubuntu@ip-10-250-69-130.us-west-2.compute.internal hostname -f ";
echo exec($commands);