Jump to content

Recommended Posts

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;

 

Link to comment
https://forums.phpfreaks.com/topic/316270-why-i-am-i-not-receiving-my-variables/
Share on other sites

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.

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.