i have test.html and test.php file uploaded to /var/www/html in my AWS Amazon EC2
URL of test.html is : http://ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.html
URL of test.php is: http://ec2-11-11-111-11.ap-northeast-1.compute.amazonaws.com/test.php
test.html is:
<!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 is:
<?php
$data = $_POST['testdata'];
echo "success";
?>
I am expecting to get alert("success"); when I click the "click me" button, but I am getting nothing.
i get alert("Post to PHP"); when I click on the button. so it seems that both of the files are working except $.post(); What am i doing wrong here??