Javascript $.post到Amazon EC2中的php文件不';好像不行
我已将test.html和test.php文件上载到AWS Amazon EC2中的/var/www/html test.html的URL为: test.php的URL为: test.html是:Javascript $.post到Amazon EC2中的php文件不';好像不行,javascript,php,ajax,post,amazon-ec2,Javascript,Php,Ajax,Post,Amazon Ec2,我已将test.html和test.php文件上载到AWS Amazon EC2中的/var/www/html test.html的URL为: test.php的URL为: test.html是: <!DOCTYPE html> <head> <script type="text/javascript" charset="utf-8"> function myFunction(){ var url = "http
<!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>
函数myFunction(){
变量url=”http://ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.php";
var data=“测试数据字符串”;
警报(“发送到PHP”);//检查javascript是否正常工作
$.post(url,{testdata:data},
函数(echo){alert(echo);};
}
点击我
test.php是:
<?php
$data = $_POST['testdata'];
echo "success";
?>
我期望得到警觉(“成功”);当我点击“点击我”按钮,但我什么也没有得到
我得到警告(“发布到PHP”)当我单击按钮时。因此,除了$.post()之外,这两个文件似乎都正常工作;
我在这里做错了什么
URL1: URL2:
如果包含jquery库,js就不会有问题。我测试它成功发送post请求 您是否厌倦了在脚本标记中包含JQuery最新文件?看看这个例子: