마지막으로이 DataTable을 사용할 수 있습니다. 하지만 이제 열을 하나 더 추가하려고했지만 더 이상 작동하지 않습니다. 왜 이런거야?
7 개의 열로 잘 작동합니다. 이제 8에서는 작동하지 않았고 그 오류가 발생합니다.
7 개의 열에 대한 전체 작업 코드는 다음과 같습니다.
PHP 코드 :
$loteria='7column';//it doesn't work for '8columns'
$lotto = new Lotto();
$ultimos_resultados=$lotto->last_results($loteria,$sorteos);
function objectToArray($d)
{
if (is_object($d)) {
$d = get_object_vars($d);
}
if (is_array($d)) {
return array_map(__FUNCTION__, $d);
} else {
// Return array
return $d;
}
}
$new_array = objectToArray($ultimos_resultados);
//echo '<pre>',print_r($new_array),'</pre>';
$result = array();
echo '[';
foreach ($new_array as $new_array2) {
echo '[';
foreach ($new_array2 AS $value){
if (1 == strlen($value)) {
$zero=0;
$value = '"'.$zero.$value.'"';
}
echo $value;
if($value!==end($new_array2)){ //referencias: http://stackoverflow.com/a/8780881/1883256
echo',';
}
}
echo ']';//referencias: http://www.mydigitallife.info/how-to-access-php-array-and-multidimensional-nested-arrays-code-syntax/
if($new_array2!==end($new_array)){
echo ',';
}else{ echo '';}
}
echo ']';
다음은 7 열 php 스크립트 출력 배열입니다.
[[2753,17,26,28,31,37,47],[2754,"08",10,23,26,44,56],[2755,"04",12,16,20,22,47],[2756,12,19,33,34,41,55],[2757,32,34,35,36,50,55]]
jQuery 코드 :
$(document).ready(function() {
$.ajax({
url: "ajax/default_chart_numbers_table.php",
type: "post",
data: {loteria: '7-column', sorteos: 5}, /*Number of rows*/
success : function (resp){
// would look something like ['val1','val2', 'etc']
var column_data = $.parseJSON(resp);
alert(column_data);
//alert('The element of array number [2] is:' + column_data[2]);
// adding data to datatables
// if column_data is 1 row
//$('#dataTables-melate').dataTable().fnAddData(column_data);
for (var j=0;j<=column_data.length-1;j++){
// adding each row with its column data
//iterating values to add leading zeros to single digits:
$('#dataTables-melate').dataTable().fnAddData(column_data[j]);
}
},
error: function(jqXHR, textStatus, ex) {
console.log(textStatus + "," + ex + "," + jqXHR.responseText);
}
});
} );
HTML DataTables 코드 :
<table id="dataTables-melate" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>Concurso</th>
<th>R1</th>
<th>R2</th>
<th>R3</th>
<th>R4</th>
<th>R5</th>
<th>R6</th>
<!--<th>R7</th> THIS IS FOR 8th column-->
</tr>
</thead>
<tfoot>
<tr>
<th>Concurso</th>
<th>R1</th>
<th>R2</th>
<th>R3</th>
<th>R4</th>
<th>R5</th>
<th>R6</th>
<!--<th>R7</th> THIS IS FOR 8th column-->
</tr>
</tfoot>
</table>
여기까지 모든 것이 괜찮습니다 ... 그러나 PHP 스크립트 출력 배열에 다음과 같은 8 개의 열이있을 때 :
[[2753,"08",16,21,39,50,52,"04",],[2754,11,18,31,35,39,42,34],[2755,"04",20,29,31,44,48,49],[2756,"05","06",33,34,46,55,38],[2757,"06",18,36,48,50,52,28]]
그런 다음 더 이상 작동하지 않으며 여기에 다음 오류가 발생합니다.
SyntaxError : JSON.parse : JSON 데이터의 1 행 33 열에 예기치 않은 문자가 있습니다.
물론 HTML 코드에 열을 하나 더 추가합니다.
버그가 어디에 있는지 모르겠습니다. 이 문제를 어떻게 해결합니까?
33 번째 문자 (두 번째 데이터 세트) 바로 앞에 추가 쉼표가 있습니다.
[[2753,"08",16,21,39,50,52,"04", <<<
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다