如何在参数列表“错误后解决”Uncaught SyntaxError:missing)

时间:2015-06-03 13:06:24

标签: javascript php jquery excel jquery-ui

我正在努力建立一个项目,项目的一部分正在将excel单元格中的所有数据检索到一个数组中,以便像autocomplete module link中那样自动提取jquery。

到目前为止,我已经实现了将excel的数据放入 PHP 数组,而不是通过帮助 Json_encode 转换为 JQuery 数组并使用flattenArray函数我的数据是一维数组。

当我的数据来自基本的Excel数据时,自动完成功能正常工作,如下所示:enter image description here

然而,当我把这样一些复杂的数据放入时: enter image description here

当数据完全进入我的

时,我在参数列表之后遇到问题未捕获的SyntaxError:缺失
 $(function(){var availableTags = $.parseJSON('<?php echo json_encode($myFlatArray); ?>');

我的问题如何防止出现此错误并且自动填充功能正常?

编辑: 这是我的代码......

    <?php

set_include_path(implode(PATH_SEPARATOR, [
    realpath(__DIR__ . '/Classes'), // assuming Classes is in the same directory as this script
    get_include_path()
]));
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';
require_once 'PHPExcel.php';

$file= "./uploads/".$_GET["filename"];
$inputFileName = ($file);

//  Read your Excel workbook
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}



//  Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0); 
$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestColumn();

//  Loop through each row of the worksheet in turn

$total=array();

for ($row = 1; $row <= $highestRow; $row++)
{ 
    //  Read a row of data into an array

    $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
                                    NULL,
                                    TRUE,
                                   FALSE);

//  echo "-----------------as rowData---------------";

//  var_dump($rowData); //  Insert row data array into your database of choice here

//    echo "-----------------VAR_DUMP total!---------------";

    array_push($total, $rowData);
//  var_dump($total);
    $myFlatArray = PHPExcel_Calculation_Functions::flattenArray($total);    
    echo    "<br>";

    echo "----------------- KOVA as json encode---------------";
    var_dump(json_encode($myFlatArray));
}

?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>


  <script>
  $(function(){var availableTags = $.parseJSON('<?php echo json_encode($myFlatArray); ?>');
    $( "#tags" ).autocomplete({source: availableTags});
  });
  </script>
</head>
<body>
 <br>
 <br>
 <br>
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
  <br>
  <br>
  <br>
  <br>

</div>


</body>
</html>

0 个答案:

没有答案