Background: I'm using Apache with XAMPP to set up localhost. I'm relatively new to programming, and very new to PHP. I'm trying to call a PHP file in the same directory as my Javascript file, but the code I'm using doesn't seem to work. Here's a sample:
Javascript:
function SendPhps(){
var point = 2;'
$.post('json.php',point);}
$(document).ready(function(){
SendPhps();
});
PHP:
<?php
if(!empty($_POST)){
file_put_contents('example.txt','Itworks');
}
?>
EDIT: Ok, I've revised my scripts to be more simple, but opening my page still doesn't trigger any alert box:
PHP:
<?php
if (empty($_POST))
echo "empty";
else
echo "not empty";
?>
Javascript:
$(document).ready(function() {
var point = {'param':2};
$.post(
'json.php',
point,
function(data){
alert(data);
}
);
});