waste of time

主にPHP

ajaxで返ってきたjsonの参照ができなくてちょっと悩んだ話

$.post(requestURL, params, function(res) {
    console.log(res.hoge);
});

ajaxで受け取ったjsonデータを上記のように参照しようとしたらundefinedが返ってきた。 $.post()の最後にdataTypeをちゃんと指定してねってことだった。

$.post(requestURL, params, function(res) {
    console.log(res.hoge);
}, 'json');

JSON.parse()してもアクセスできるけど。

jQuery.post() | jQuery API Documentation