CodeRed-Alpha Posted May 8, 2023 Share Posted May 8, 2023 I am just trying to pass 2 simple variables from my jaascript to my php page. My php is not receiving them. Why not? Javascript function. function removeNotification(Record_Id){ var remove = { remove_id: Record_Id, queue: "Documents", }; let remove_data=new XMLHttpRequest() remove_data.open("POST", "scripts/Notifications_Delete.php", true); remove_data.setRequestHeader("Content-Type", "application/json"); remove_data.onreadystatechange=function(){ if (remove_data.readyState===4 && remove_data.status===200){ console.log(Record_Id); } }; remove_data.send(JASON.stringify(remove)); } My PHP to receive it. $remove = json_decode(file_get_contents("php://input"), true); $Remove_Id = $remove["remove_id"]; $Queue_Name = $remove["queue"]; echo 'Your Remove ID is: '.$Remove_Id; Quote Link to comment Share on other sites More sharing options...
kicken Posted May 8, 2023 Share Posted May 8, 2023 Check your browsers development console for error messages. I'm assuming you'll see one about how JASON is not defined. 1 Quote Link to comment Share on other sites More sharing options...
CodeRed-Alpha Posted May 8, 2023 Author Share Posted May 8, 2023 That was correct. What am i missing to define the JSON object. As I get getting a blank object and nothing more. Even my latest and most simple method is not working. No errors, just not getting any POST value. function removeNotification(Record_Id){ var evac = {}; evac.id = Record_Id; evac.queue = 'Documents'; jsonString - JSON.stringify(evac); let remove_data=new XMLHttpRequest(); remove_data.open("POST", "scripts/Notifications_Delete.php", true); remove_data.setRequestHeader("contrnt-typr", "application/x-www-form-urlencoded"); remove_data.send(jsonString); } My PHP side is not getting anything. If I console.log the jsonString at the point of send, I am getting the object there. but not receiving it. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 8, 2023 Share Posted May 8, 2023 3 minutes ago, CodeRed-Alpha said: "contrnt-typr", ??? Quote Link to comment Share on other sites More sharing options...
CodeRed-Alpha Posted May 8, 2023 Author Share Posted May 8, 2023 I corrected the typos. I believe I am getting at least a response on the POST. In my if(isset($_POS I have a redirect which it seems to be hitting. Should I be reading as $_POST['evac.id'] or what? I have echo '<script console.log("Echo This")</script>'; How to print my array to the console log just to see how they are named and values? Quote Link to comment Share on other sites More sharing options...
CodeRed-Alpha Posted May 8, 2023 Author Share Posted May 8, 2023 36 minutes ago, Barand said: ??? Yep i spotted that as well and that did have an affect. My eyes are so bad, certain characters are hard to distinguish. Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.