2014-03-29 8 views
0

여기 두 Dimensional array을 가져 오는 기능을 만들었습니다. 제대로 작동하지만 여기서도 한 행을 삽입하고 있습니다. 함수를로드하는 행을 삽입 한 후 데이터를 가져올 수 없습니다.ajax json에서 multidimstional 배열을 사용하는 방법?

function get_company_expenses_type(element_id) { 
    $.ajax({ 
     url: "../../modal/system_operator/get_companyexpenses_type.php", 
     dataType: "html", 
     type: 'POST', 
     success: function (json) { 
      var result = jQuery.parseJSON(json); 
      length = result.len; 
      for (k = 1; k <= length; k++) { 
       $('#' + element_id + ' option').last().after('<option value="' + eval("result.row" + k + ".company_expenses_type_id") + '">' + eval("result.row" + k + ".company_expenses_type") + '</option>'); 
      } 
     } 
    }); 
} 
$(document).ready(function() { 

    var cnt = 1; 
    $("#anc_add").click(function() { 
     cnt++; 
     $("input[id=rows]").val(cnt); 
     $('#tbl1 tr').last().after('<tr><td><select name="' + cnt + '1"><option value="0">Select Expenses Type</option>X</select></td><td><textarea name="' + cnt + '2"></textarea></td><td><input type="text" name="' + cnt + '3"></td></tr>'); 
     element_id = cnt + '1'; 
     alert(element_id); 
     $.ajax({ 
      url: "../../modal/system_operator/get_companyexpenses_type.php", 
      dataType: "html", 
      type: 'POST', 
      success: function (json) { 
       var result = jQuery.parseJSON(json); 
       length = result.len; 
       for (k = 1; k <= length; k++) { 
        $('#' + element_id + ' option').last().after('<option value="' + eval("result.row" + k + ".company_expenses_type_id") + '">' + eval("result.row" + k + ".company_expenses_type") + '</option>'); 
       } 
      } 
     }); 
    }); 

    get_company_expenses_type(cnt + '1'); 
    $("#anc_rem").click(function() { 
     if (cnt > 1) { 
      cnt--; 
      $("input[id=rows]").val(cnt); 
      $('#tbl1 tr:last-child').remove(); 
     } 
    }); 

}); 

답변

0

dataType을 html에서 json으로 변경하십시오.

dataType: "html", 

problem.bcoz 데이터가 첫 행에 대해 가져 오는 중 오류입니다 아니에요

dataType: "json", 
+0

합니다. – user3363946

관련 문제