目前有一種方法,用jquery ajax傳給服務端,服務端用php寫入Excel。但是,現在服務端根本收不到ajax資訊,請大師分析原因。
Ps: 已搭建WampServer 環境,也已測試localHost。
貼上服務端PHP代碼:(網上找的demo)
header("content-type:application/json; charset:utf-8");
date_default_timezone_set("Asia/Shanghai");
$firstAccess = null;
$rawData = file_get_contents("php://input");
$parameters = json_decode($rawData);
if($parameters){
if(isset($parameters->url)){
$currMd5 = md5($parameters->url);
$handle = fopen("history.txt", "r+");
if ($handle) {
while (($line = fgets($handle, 4096)) !== false) {
if(0===strpos($line, $currMd5)){
$firstAccess = trim(substr($line, 33));
break;
}
}
if(!$firstAccess){
$firstAccess = date("Y-m-d H:i");
fwrite($handle, $currMd5." ".$firstAccess."\r\n");
}
fclose($handle);
}
else {
exit(json_encode(array ('error'=>'伺服器意外錯誤.')));
}
exit(json_encode(array ('firstAccess'=>$firstAccess)));
}
}
exit(json_encode(array ('error'=>'請求不正確.')));
?>
回複討論(解決方案)
有碰到過同樣問題的兄弟嗎?求有經驗的大哥幫忙?(小弟是PHP新手)