It is necessary to transfer an array of idshnik using AJAX in php , but error 400 comes out of the console (wrong parameters)
I wrote this code on js :
var xhr = new XMLHttpRequest(); var body = JSON.stringify({ id: checkedInputTagsArray //ΠΌΠ°ΡΡΠΈΠ² ΠΈΠ΄ΡΠ½ΠΈΠΊΠΎΠ² }); console.log(body); xhr.open('POST', '/products/' + action , true); //action - ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡ ΡΡΠ½ΠΊΡΠΈΠΈ xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8'); xhr.send(body); php code:
$request = Yii::$app->request; if (!$request->isAjax) { return "not ajax"; } $json = json_encode($request->getBodyParams()); return $json; Yes, it does nothing, but I would first establish a connection and see if the data is being transmitted.
Is there any difference between open(..., /model/action) and open(..., http://host/model/action) ? Just with my host, my debugger does not display Ajax requests ...
json_encodewithjson_decodebecause the encode function converts the object into a JSON string, and you need to do the opposite - Sergey-N13