1
何とか私のjsonオブジェクトへのアクセス方法をajax呼び出しから見つけることができません。その後、私はデータを使ってアクセスしたいajax成功のJSONオブジェクトへのアクセス
echo json_encode(array(
"nextId" => 2
));
:ハンドラで は、私は次のIDをエコーてる
$.ajax({
[...],
dataType: 'json',
success:function(data) {
console.log(data)
console.log(data['responseText'];
console.log(data['responseText'].nextId);
console.log(data['responseText']['nextId']);
}
});
Result: Object {readyState: 4, responseText: "{"nextId":2}", responseJSON: Object, status: 200, statusText: "OK"}
Result: {"nextId":2}
Result: Undefined
Result: Undefined
私が見てNEXTID
ログでわかるように、 'data.responseText'の値は**文字列**です。 jQueryを使用していますか? jQueryは自動的に応答をデコードする必要があります。あなたが成功関数の第一引数としてその価値を得ていることは奇妙に思えます。 –
私はあなたが 'console.log(data ['responseJSON']。nextId);'にもっと運があると思います。 – MacPrawn
@MacPrawnがうまくいきました。答えを提出する。 –