我已经尝试解决这个问题一个多星期了,但我似乎无法解决这个问题,尤其是因为我绝对没有收到任何错误消息。
我想使用 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 在我的服务器上运行良好。
它以前有效,我只是复制粘贴这些行,但现在无效。
最佳答案
我已经弄明白了: 这是因为我弄乱了路径,我在 $ajax() 函数中添加了无用的参数(缓存、内容类型、进程数据)
关于javascript - ajax post to file 函数什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52355436/