私はJqueryとAjaxを初めて使用します。この投稿の助けを借りて、フォームのコンボ ボックスのオプションをクリックした後にフォームを自動入力する次のコードを作成しました。
$("select#student_id").change(function(){
var student_id = $(this).val(); //Here I am getting the selected value from
//the combo box
$.ajax({
url: "/students.json?student_id="+student_id, //this is the url that will
//send me one student object
dataType: "json",
success: function(student) {
$('#student_email').val(student.email);
$('#student_roll_num').val(student.roll_num);
}
});
});
しかし、これらの値student.email, student.roll_num
はすべて空白になり、ステートメントを発行すると、そのようalert(student)
に印刷[object object]
されます。しかし、ブラウザーで同じ json 呼び出しを呼び出すと、学生の期待される json オブジェクトが取得され、そこですべての学生属性の正しい値が取得されます。上記のコードのどこかで間違っていますか? 誰かがこれを修正するのを手伝ってくれたら、本当に感謝します。ありがとうございました。