目前有一种方法,用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新手)
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号