2015-03-02 71 views
0

我已經和test.html的文件test.php的上傳到test.html中的我的AWS的Amazon EC2

URL的/ var/www/html等是: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(); 我在這裏做錯了什麼?

+0

您是否厭倦了在腳本標記中包含JQuery最新文件?看看這個例子:http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_post – AkshayP 2015-03-02 07:17:32

回答