javascript - ajax post to file 函数什么都不做

标签 javascript php jquery ajax post

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

我想使用 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/

相关文章:

php - 通过 wp_nav_menu_items 添加类到 Wordpress 菜单

javascript - Ajax Post请求示例

javascript - 为什么在 Chrome 而不是 Firefox 中将条件 block 中的函数声明提升到函数范围?

javascript - 如何有效地将搜索添加到 html 表单中?

php - 如何从 Controller 中的函数返回多个变量

jquery - 使用 jQuery 设置宽度后,选择的宽度减少了 2px

javascript - 为什么 line-through 仅适用于此 jQuery 待办事项列表中的所有其他元素?

javascript - 将js对象转换为字符串映射(与通常的字符串到对象相反)

javascript - 跨数组访问对象值

PHP 调整图像大小并保存透明 PNG