【发布时间】:2015-03-02 07:11:18
【问题描述】:
我已将 test.html 和 test.php 文件上传到我的 AWS Amazon EC2 中的 /var/www/html
test.html 的 URL 是:http://ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.html
test.php的网址是:http://ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.php
test.html 是:
<!DOCTYPE html>
<head>
<script type="text/javascript" charset="utf-8">
function myFunction(){
var url = "http://ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.php";
var data = "test_data_string";
alert("Post to PHP"); //check to see if javascript is working
$.post(url, {testdata:data},
function(echo){alert(echo);});
}
</script>
</head>
<body>
<button onclick="myFunction()">Click me</button>
</body>
</html>
test.php 是:
<?php
$data = $_POST['testdata'];
echo "success";
?>
我希望得到警报(“成功”);当我点击“点击我”按钮时,我什么也没得到。
当我点击按钮时,我得到 alert("Post to PHP");。所以似乎这两个文件都在工作,除了 $.post(); 我在这里做错了什么?
【问题讨论】:
-
您是否厌倦了在脚本标签中包含 JQuery 最新文件?看看这个例子:w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_post
标签: javascript php ajax post amazon-ec2