Answer the question
In order to leave comments, you need to log in
Sending object to server, encoding problems (json,stringify,json_encode)?
Good day friends, I send an object to the server:
javascript
var json = [{"key":"29","value":"Country"},{"key":"30","value":"4,3,5"}];
var xhr = new XMLHttpRequest();
xhr.open('POST', 'read.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('json=' + JSON.stringify(json)); //[{"key":"29","value":"Country"},{"key":"30","value":"4,3,5"}];
<?php
if (!isset($_POST['json'])) exit;
$fn = 'myjson.json';
file_put_contents($fn, json_encode($_POST['json']));
"[{\"key\":\"29\",\"value\":\"Country\"},{\"key\":\"30\",\"value\":\"4,3,5\"}]"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question