对不起英语不好:)
我试图以 json 格式为用 php/python 编写的 restapi 发布表单。如果我使用 json ,我将无法访问发布的数据。看下面的场景
非 json 帖子的代码
jQuery(document).ready(function($) {
$.post(
"http://localhost:8000/api/v1/entry/?format=json",
{
"body": "This will prbbly be my lst edited post.",
"pub_date": "2011-05-22T00:46:38",
"slug": "another-post",
"title": "Another Post",
"username":"admin",
"password":"admin"
},
function(responseText){
$("#result").html(responseText);
},
"html"
);
})
服务器响应
Array
(
[body] => This will prbbly be my lst edited post.
[pub_date] => 2011-05-22T00:46:38
[slug] => another-post
[title] => Another Post
[username] => admin
[password] => admin
)
Json Post 代码
jQuery(document).ready(function($) {
var data = JSON.stringify({
"body": "This will prbbly be my lst edited post.",
"pub_date": "2011-05-22T00:46:38",
"slug": "another-post",
"title": "Another Post",
"username":"admin",
"password":"admin"
});
$.post(
"testpost.php",
data,
function(responseText){
$("#result").html(responseText);
},
"html"
);
})
服务器响应
Array
(
)