【发布时间】:2015-06-22 22:31:48
【问题描述】:
我正在尝试为一个项目构建一个小型 CMS。部分原因是,当您单击save-button 时,您当前的编辑将被保存。
$('.save-button').click(function() {
var speisekarte_content = $(".speisekarte-content").html();
console.log(speisekarte_content);
var ajaxurl = 'save.php',
data = {
'content': speisekarte_content
};
$.post(ajaxurl, data, function(response) {
alert("action performed successfully");
});
});
save.php 看起来像这样:
<?php
$post_data = $_POST['content'];
if (function_exists('fopen')) {
if (!empty($post_data)) {
$filename = 'speisekarte-content.php';
$handle = fopen($filename, "w");
fwrite($handle, $post_data);
fclose($handle);
echo $file;
}
};
?>
所以它基本上只是将应该保存的内容添加到一个名为 speisekarte-content.php 的文件中……这在 localhost 上运行良好——直到我将它上传到我的 nginx 服务器并且它按预期停止工作。
这是我在 javascript 控制台中找到的错误日志:
POST
http://www.myurl.com/editable/save.php net::ERR_TIMED_OUT
k.cors.a.crossDomain.send @ jquery.min.js:4
n.extend.ajax @ jquery.min.js:4
n.(anonymous function) @ jquery.min.js:4
(anonymous function) @ main.js:99
nginx错误日志如下
2015/06/22 08:43:45 [error] 6804#0: *63817 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: content in /var/www/myurl.com/html/editable/save.php on line 2
PHP message: PHP Warning: fopen(autosave.php): failed to open stream: Permission denied in /var/www/myurl.com/html/editable/save.php on line 27
PHP message: PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/myurl.com/html/editable/save.php on line 28
PHP message: PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/myurl.com/html/editable/save.php on line 29
PHP message: PHP Notice: Undefined variable: file in /var/www/myurl.com/html/editable/save.php on line 30" while reading response header from upstream, client: 176.0.1.54, server: myurl.com, request: "POST /editable/save.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.myurl.com", referrer: "http://www.myurl.com/editable/"
这与nginx或我的代码有关吗?
【问题讨论】:
-
console有什么要说的? -
@Daan 允许连续设置两个变量。 Retador,你检查过文件权限、htacess 等吗?
-
@Tushar 我在上面发布了错误日志……否则它会用
speisekarte-content类记录我的 div 的内容 :) -
你查看过服务器上的错误日志吗?
-
如果 nginx 日志中的 第一条错误消息 对你来说很神秘,那么我不得不说我认为你是在 完全错误的工作。它至少应该给你一个线索来谷歌搜索!
标签: php jquery ajax post nginx