0

jqueryを使用したAJAXは初めてです。以下のようなjson応答があります。

[{"customer_name":"Customer A"},{"customer_name":"Customer B"},{"customer_name":"Customer C"}]

そして、私のajaxファイルは次のとおりです。

 function(result){
    $('#resdiv').html(result);
    console.log(result);
    var json_obj = $.parseJSON(result);//parse JSON
    alert(json_obj);

    var output="<ul>";
    for (var i in json_obj)
    {
    output+="<li>" + json_obj[i].customer_name + "</li>";
    }
    output+="</ul>";
    $('#resdiv1').html(output);
}

div id でJSON 応答を表示できますがresdiv、div idresdiv1は空です! またalert(json_obj);、何も警告しません! ファイルの何が問題になっていますか?

NB: Zuch Tutorialから学んでいます

4

3 に答える 3

1

これをチェックしてください

// Need to parse if string.
var result = '[{"customer_name":"Customer A"},{"customer_name":"Customer B"},{"customer_name":"Customer C"}]';
var json_obj = $.parseJSON(result);//parse JSON

// No need to parse
var json_obj = [{"customer_name":"Customer A"},{"customer_name":"Customer B"},{"customer_name":"Customer C"}];

こちらもチェック

// if undefined, you don't have resdiv1 div or you have call function before your div render.
alert($('#resdiv1').html());
于 2013-11-09T07:57:37.077 に答える