首页 > 解决方案 > ajax post to file函数什么都不做

问题描述

我已经尝试解决这个问题一个多星期了,但我似乎无法解决这个问题,特别是因为我绝对没有收到任何错误消息。

我想使用 jQuery AJAX 将单个变量发布到本地文件,这是我的代码:

JS:

var args = "true,true,false,false,false,false,false,true"; //(just an example)
alert("sending request");
$.ajax({type: 'post', dataType: 'text', cache: false, contentType: false, processData: false, url: '/submitvote.php', data: {data: args}, success: function(php_script_response){alert("response: " + php_script_response);}});

提交投票.php:

<?php
    $pdata = $_POST['data'];
    @file_put_contents('admin/votes.txt', $pdata, FILE_APPEND | LOCK_EX);
?>

第一个 alert() 被执行,但它不执行成功函数,并且绝对没有向文件发布任何内容。PHP 在我的服务器上运行良好。

它以前工作过,我刚刚复制粘贴了这些行,但现在不起作用。

标签: javascriptphpjqueryajaxpost

解决方案


我已经想通了:这是因为我弄乱了路径,并且我在 $ajax() 函数中添加了无用的参数(缓存、contentType、processData)


推荐阅读