我正在尝试为项目构建一个小型CMS。部分原因是,当您点击save-button
时,您当前的编辑将被保存。Ajax post在localhost上运行,但在nginx服务器上运行
$('.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
文件中的内容。这工作完全在本地主机上 - 直到我将它上传到我的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'不得不说什么? – Tushar
@Daan它允许在一行中设置两个变量。 Retador,你有没有检查文件权限,htacess等? –
@Tushar我在那里发布了错误日志......否则它会记录我的div与speisekarte-content'类的内容:) – Retador