英語が下手でごめんなさい:)
php/pythonで書かれたrestapiのフォームをjson形式で投稿しようとしていました。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
)
JsonPostのコード
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
(
)