Ajax code not working with php but data response getting in console page, This is on page load and i think its because page is getting loaded with get method but unable to change it to post as i am not submitting a form. please help.
CodePudding user response:
$.ajax({ url:"../../assets/php/fetcheachcategory.php", method: "POST", data: {jobdetails: JSON.stringify(jobdetails)}, success:function(res){ console.log(res); } })
When i am getting the $_SERVER['REQUEST_METHOD']; i am getting get method and my data is not getting visible in php. I am getting it in console data as an array.
CodePudding user response:
$.ajax({
url:"../../assets/php/fetcheachcategory.php",
method: "POST",
data: {jobdetails: JSON.stringify(jobdetails)},
success:function(res){
console.log(res);
}
})
-------------------------------------------
PHP
echo $_SERVER['REQUEST_METHOD'];
echo $job = $_POST['jobdetails'];
echo $job;
-----------------------------------------------
console response
POST"Self Employment""Self Employment"Array
(
[jobdetails] => "Self Employment"
)
-------------------------------------------------
PHP server
GET Array ( )