[英]Posting to text file using AJAX?
How do you post this AJAX request to a text file? 您如何将此AJAX请求发布到文本文件? The url it is posting to is something along the lines of submit.php, but I can't seem to figure out how to save it properly to a file named "data.txt"
它发布到的URL类似于submit.php,但是我似乎无法弄清楚如何正确地将其保存到名为“ data.txt”的文件中
function makeAjaxRequest(cData) {
var promise = $.ajax({
type: "POST",
url: url,
data: cData,
dataType: 'json',
async: true
});
promise.done(successFunction);
promise.fail(errorFunction);
promise.always(alwaysFunction);
}
The data itself is already fo the format using data = JSON.stringify(collectedData);
数据本身已经是使用
data = JSON.stringify(collectedData);
的格式data = JSON.stringify(collectedData);
in a previous statement. 在之前的声明中。
EDIT: I guess the wording I used is poor, sorry. 编辑:我想我用的措词很差,抱歉。 I intend to pass the data into submit.php using the POST method.
我打算使用POST方法将数据传递到Submit.php中。 I would like that submit.php file to concat the text to a text file.
我希望该commit.php文件将文本合并为文本文件。
Currently the submit.php file contains the following: 当前,submit.php文件包含以下内容:
<?php file_put_contents('mydata.txt', $data, FILE_APPEND | LOCK_EX); ?>
I didnt see how you retrieved the ajax data, since $data
is undefined in your code, try this: 我看不到如何检索ajax数据,因为
$data
在代码中未定义,请尝试以下操作:
<?php
$data = file_get_contents('php://input');
file_put_contents('mydata.txt', $data, FILE_APPEND | LOCK_EX);
?>
This will write json strings to mydata.txt
这会将json字符串写入
mydata.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.