I am trying to send some data to Php with Ajax and then sending back a result to Ajax. Thing is that Ajax gives me an empty error and I cant find what the problem is. Is there something wrong in the PHP script?
Ajax code
$.ajax({
type: POST,
url: PHPfileLink,
data: {'data1': test, 'data2': asd},
success:function(data){
document.getElementById('testDiv').innerHTML = data;
},
error:function(request,textStatus,error){
alert(error);
}
});
}
PHP code
<?PHP
//$a = $_POST['data1'];
//$b = $_POST['data2']
$name = "qwerty";
$age = 100;
$arr = array('name' => $name, 'age' => $age);
echo json_encode($arr);