In .js I want to send some multi data in json using ajax. I have problem receiving them in my php
js:
$("#mybtn").on('click'.function(){
$.ajax({
type:'POST',
url: 'handler.php',
data: JSON.stringify({taskId:2 , infos:"blahblah"}),
headers:{
'content-type':'application/json'
},
success: function(response){alert "response";},
error: function(){alert "error";}
});
});
for example how can i ,if taskid is 1, write infos in debug.txt?
handler.php:
<?php
$temp = $_POST; //also i put $_REQUEST not usefull
file_put_contents('D:\debug.txt',$temp);
//$temp2 = data I don't know how to do it!
if($temp2['taskId']==1){
file_put_contents('D:\debug.txt',$temp2['infos']);
?>