繁体   English   中英

$ .post到Amazon EC2中的php文件似乎不起作用

[英]$.post to php file in Amazon EC2 doesn't seem to work

我在我的AWS Amazon EC2中将test.html和test.php文件上传到了/ var / www / html

test.html的网址是: http : //ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.html

test.php的URL是: 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";
?>

我期望得到警报(“成功”); 当我单击“单击我”按钮时,我什么也没得到。

我收到警报(“发布到PHP”); 当我单击按钮时。 因此,除了$ .post();以外,这两个文件似乎都可以正常工作。 我在这里做错了什么?

  1. 这两个URL不可访问 ,我不确定您在做什么,但是将php文件置于在线并不意味着它可访问并且将作为脚本运行。
    网址1: http//ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.html

    网址2: http//ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.php

  2. 包括jQuery

更新:
如果包含jquery库,您的js不会有问题。 我测试了它成功发送了发帖请求。 jsFiddle

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM