true]); } else { echo json_encode(['success' => false]); } exit; } // 后面的代码不变... header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST'); header('Access-Control-Allow-Headers: Content-Type'); $dataFile = 'dataurl.json'; // 确保文件存在 if (!file_exists($dataFile)) { file_put_contents($dataFile, '[]'); } $method = $_SERVER['REQUEST_METHOD']; if ($method === 'GET') { // 读取数据 $data = file_get_contents($dataFile); echo $data; } elseif ($method === 'POST') { // 保存数据 $input = file_get_contents('php://input'); $data = json_decode($input, true); if ($data !== null) { file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); echo json_encode(['success' => true]); } else { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Invalid JSON']); } } ?>