I need pass jQuery variable to PHP variable, so I made simple code to test and it doesn't work.
It's only a testing files. Finally, I have to do something more advanced but i can't make it works!
I have 3 files
In character.html I have:
<a href="character-save.php" class="saved">SAVE</a>
and in character.js (it's external javascript for character.html)
$(document).ready(function() {
$('.saved').click( function () {
var avatarID = 123;
$ajax({
url :'character-save.php',
data:{"avatarID":avatarID},
type: 'post',
dataType: 'json',
});
});
});
in character-save.php i try this:
<?php
header('Content-type: application/json');
$result = $_POST['avatarID'];
$result = htmlentities($result, UTF-8);
echo json_encode($result);
exit();
?>
And it doesn't print 123
'UTF-8'. Second - what does it print? (though I guess it prints nothing)