'Not able to get sent JSON data in WordPresss page
Our website is on WordPress, I had converted all the HTML pages into custom WordPress pages using a custom WordPress template. I have uploaded one js file in the header and that js file has the below code on button image click. When the user clicked on the button image from the WordPress page, it will get the data into "stringifyPayloadData" and this data is coming from the js session. And I want to send this data on the same page (from where we clicked) because I want those data in PHP variable so that I can do other PHP functionality by using this JSON data.
$.ajax({
type: "POST",
dataType: "json",
url: "http://localhost/nexplanontraining/request-clinical-training/in-person-training/training-registration-review/",
data: stringifyPayloadData,
//contentType: "application/json",
success: function(data){
alert("Data Sent");
},
error: function(e){
console.log(e.message);
}
});
And below is my php code to get data into the same page, but it's not working.
echo json_encode($_POST);
$jsonString = file_get_contents("php://input");
echo $jsonString;
$phpObject = json_decode($jsonString);
echo $phpObject;
I have a button image on the same page where I want that session data into PHP variable on click event that's why I use AJAX request on click. and try to send data to the same page by giving the URL of the page. I got a "Data Sent" alert but did not get data into the WordPress page. Is there any other way to get data on the WordPress page?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
