I am trying to pass a single variable from javascript to PHP using jQuery AJAX.
Javascript:
$(document).ready(function() {
$('.ok').on('click', function(e){
var value = 5;
$.ajax({
url: 'tabulka.php',
type: "POST",
data: {x : value},
success: function(){
alert(value);
}
});
});
});
PHP:
if($_SERVER['REQUEST_METHOD']){
$value = $_POST['x'];
echo $value;
}
I get the alert from ajax with the expected value but in PHP I get this error: Notice: Undefined index: value in C:\xampp\htdocs\test\tabulka.php on line 71
When I uncomment the dataType: 'json' I don't even get the alert from AJAX.
['value']is being used as an array index.