Your Location is: Home > Php

ajax error: SyntaxError: Unexpected token < in JSON at position 0

From: Canberra View: 5040 이기엽 
 php

Question

> $sql_get_col = "SELECT ";
> 
> for ($i=0; $i < $select_obj_length ; $i++) {   if($i ==
> $select_obj_length-1){
>     $sql_get_col .= $select_obj_arr[$i];
>     break;   }   $sql_get_col .= $select_obj_arr[$i].","; }
> 
> if($sensor_location == 193){   $table_name =
> '[SWIQ_data].[dbo].[swiqdata_table]'; }else if($sensor_location ==
> 200){   $table_name = '[SWIQ_data].[dbo].[waterkorea_swiq]'; }else{  
> print_r("ERROR FXX ."); }
> 
> //$sql_get_col .= " FROM ? WHERE date_time BETWEEN '?' AND '?'";
> $sql_get_col .= " FROM $table_name WHERE date_time BETWEEN
> '$start_date' AND '$finally_date'"; //$sql_get_col .= " FROM
> ".$table_name.' WHERE date_time BETWEEN '."$start_date".' AND
> '."$finally_date";
> 
> 
> $options = array("Scrollable" => SQLSRV_CURSOR_KEYSET); $params =
> array(); // $params = array(3, $table_name, $start_date,
> $finally_date);  //$params = array(&$table_name, &$start_date,
> &$finally_date);
> 
> print_r($sql_get_col);
> 
> $result = sqlsrv_query($con, $sql_get_col, $params, $options);
> $total_record = sqlsrv_num_rows($result);
> 
> $result_val = array(); for ($i=0; $i < $total_record; $i++){
>     $row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC);
>     for ($j=0; $j < $select_obj_length ; $j++) {
>       // $abc = $select_obj_arr[$j];
>       array_push($result_val, array($select_obj_arr[$j]=>trim($row[$select_obj_arr[$j]])));
>     }
> 

When I run ajax datatype with the code above, I get an error.

However, when the query statement mode is combined, it works normally.

This statement does not generate an error. I don't know why. Help me

Best answer