I have a key value pair which i want to send to server. e.g: var obj = {'item1': true, 'item2': false,开发者_运维百科 ........};
I want to send this information to server by ajax call. But at server side i am unable to get individual value. At server side i am getting "object" as string. I am using jQuery for making an ajax call.
Can anyone please give any idea how to do it?
I got answer to my question. This can be done by using:
var obj = {'item1': true, 'item2': false, ........};
$.post("test.php", {data: JSON.stringify(obj)});
var a = $.JSON.encode(obj);
$.post("test.php", {data:a});
Use a JSON decoder to convert the string in $_POST["data"]
to an associate array at the server side.
<?php
$json = $_POST["data"]
var_dump(json_decode($json));
?>
精彩评论