jQuery ajax post json type data to php use json_decode example

from:http://stackoverflow.com/questions/2799304/sending-jsonjquery-to-php-and-decoding-it

// JS

var person = “{ name: ‘John Doe’ }"; // notice the double quotes here, this is a string, and not an object
$.ajax({
type: “POST",
url: “../bin/process.php",
dataType: “json",
data: { json: person }
});

// PHP

$json = $_POST[‘json’]; // $json is a string
$person = json_decode($json); // $person is an array with a key ‘name’

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s