大家好,这是不正常的:) !!
foo.php
<?php
if (isset($_POST['data']))
$stringData = $_POST['data'];
$file = "ciao.txt";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $stringData);
fclose($fh);
?>
file.js
function WriteToFile() {
var dataa = "foo bar";
$.post("foo.php", {data: dataa}, function(result){ alert("ciaoooo!!");}
, "json");
}
这是错误,我无法在 file.txt 上写入
注意:未定义变量:stringData
我也尝试过那种功能
function WriteToFile() {
var data = "foo bar";
$.ajax({
url: 'foo.php',
type: 'POST',
data: { 'data' : 'data'},
success: function() {
alert('the data was successfully sent to the server');
}
});
but the result is the same!! Anyone have some idea???