0

私は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 オブジェクトが取得され、そこですべての学生属性の正しい値が取得されます。上記のコードのどこかで間違っていますか? 誰かがこれを修正するのを手伝ってくれたら、本当に感謝します。ありがとうございました。

4

1 に答える 1

0

これを試してください、これはあなたを助けます。ここで、U = ページの URL および F = ページの機能

$("select#student_id").change(function(){
        var student_id = $(this).val();   
    $.ajax({
            type: "POST",
            url: U + '/' + F,
            data: "{id: " + student_id + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            cache: false,
            success: function (response) {
                var content=response.d;
            }
        });
    });
于 2013-09-15T11:12:53.403 に答える