Json encoding in php or symfony

i can’t get access to my array in php(symfony) and i don’t understand why any idea please??
i tried with both an Object

const obj= {
      media: "facebook", 
      type: "fb_profile",
      id: "2b48996c71bc33c8b5234e66cb81fe27a2a8d6233df0ac113b…a86c063ebe86bcfd21f10adc9caea5ff0eb4c3f20018c05dd"
     }

or an Array

const ary = [**strong text**
      media: "facebook",
      type: "fb_profile",
      id: "2b48996c71bc33c8b5234e66cb81fe27a2a8d6233df0ac113b…a86c063ebe86bcfd21f10adc9caea5ff0eb4c3f20018c05dd"
     ]

this is my sjs code

   el.addEventListener('click', function (e) {

            const xhrConstruct = (method, url, data) => {

                const promise = new Promise((resolve, reject) => {

                     const xhr = new XMLHttpRequest();
                     xhr.open(method, url, true);
                     xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
                     // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                     xhr.setRequestHeader('Content-Type', 'application/json');
                     // xhr.responseType = 'json';

                     xhr.onload = function (ev) {
                          resolve(xhr.response);
                     };

                    xhr.send(JSON.stringify(data));

        });

        return promise;

      };

      const getFeed = () => {
        xhrConstruct('POST', 'feed', {
          media: ary["media"], // or obj.media
          type: ary["type"], // or obj.type
          id: ary["id"] // or obj.id
        }).then(responseData => {
          console.log(responseData);
        });
      };

      getFeed();



    }, false);

and my php(symfony) si simple i want only to access the info sent with tha ajax

public function feed(Request $request)
    {

        // if  ajax
        if($request->isXmlHttpRequest()){
            var_dump($request->request);
            var_dump($_POST);
            var_dump($_GET);
            die();
        }
    }

all three are emty

object(SymfonyComponentHttpFoundationParameterBag)#95 (1) {
    ["parameters":protected]=>
    array(0) {
    }
}

array(0) {
}

array(0) {
}

any idea how to acces the data thank you in advance

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

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