function displayData_datalist(tID,file,field,whereString) { t_url="<?=AWS?>/ETC/system/04_AWS/06_%E6%9F%A5%E8%A9%A2%E8%A1%A8%E6%A0%BC/04_webservice_json.php?action=select&file="+file+"&field="+field; console.log(t_url); $.ajax({ url: '<?=$path?>/04_AWS/06_查詢表格/04_webservice_json.php?action=select&field='+field, data: {'url':encodeURI(t_url),'tID':tID,'file':file,'field':field,'where':whereString}, type: 'GET', contentType: "application/x-www-form-urlencoded; charset=utf-8", dataType:'json', async:true, success : function(data) { if(tID!="委託項目1_list") { var nameArray = data['data']; var lastvalue = null; $.each(nameArray, function (i, item) { t1 = "#" + tID; //console.log(item[field]); if (lastvalue != item[field]) { $(t1).append($("<option>").attr('value', item[field]).text(item[field])); lastvalue = item[field]; } }); } }, error : function(request,error) { console.log("error"); } }); }
而PHP那邊
$fxls = isset($_GET['file']) ? $_GET['file'] : 'test.xls'; $fxls2 ='files/'.$fxls; $action = isset($_GET['action']) ? $_GET['action'] : 'select'; $ext = strtolower(pathinfo($fxls2 , PATHINFO_EXTENSION)); $tID = isset($_GET['tID']) ? $_GET['tID'] : ''; $file = isset($_GET['file']) ? $_GET['file'] : ''; $field = isset($_GET['field']) ? $_GET['field'] : ''; $where = isset($_GET['where']) ? $_GET['where'] : ''; if (is_array($arr)==true && count($arr) > 0) { echo json_encode(array( "success" => true, "id" => 1909051, "data" => $arr, "debug" => $field, "msg" => $msg, "filename" =>$fxls, "tID" =>$tID, "file" =>$file, "field" =>$field, "where" =>$where, //"msg" => "OK", )); } else { echo json_encode(array( "success" => false, "id" => 1908273, "debug" => "file name:" . $fxls, "debug" => $msg, "msg" => $msg, //"msg" => "error", )); }