Sending body data through PHP/WordPress to my backend

enter image description here

I have in the frontend this function that sends data to the backend through a proxy in wordpress/php:

 jQuery.ajax({
                url: ICapiEndpoint,
                type: 'POST',
                data: {
                    name: document.getElementById('icName').value, //<= I NEED THIS VALUE in backend
                    action: "get_search_suggestions",
                },
                success: function (result) {
                    console.log("result",result)
                },
                error: function (error) {
                    console.log("error",error)
                }
            })

In php I got this functions:

add_action('wp_ajax_ic_copy_nodes', function() {
    $api = new ArangoConnector();
    $data = stripslashes($_POST["data"]);
    send_json_response($api->copyNodes($data));
});

And:

public function getSuggestions($data)
{
    $data = ($data);
    $json = json_decode($data);
    $url = $this->getBaseUrl() . self::SEARCH_SUGGESTIONS;
    $response = wp_remote_get($url, self::getDefaultArgs());
    return self::generateResponse($response);
}

I know its working because in my backend which is in node.js I’m printing the request and I’m getting:

As you can see there is no namevalue in there. How to receive the name value that I’m sending in the frontend. I know its something I’m missing in php.

Read more here: Sending body data through PHP/Wordpress to my backend

Leave a Reply

Your email address will not be published. Required fields are marked *