我尝试将一些JSON数据发送到PHP文件,但我得到500个内部服务器错误。
发布数据的javascript函数:
$scope.addcommentaire = function() {
var onecomment= {page:document.getElementById('hiddenpage').value, text:this.textMessage,author:this.auteur };
$http({
method : 'POST',
url : 'data/comment.php',
data: onecomment,
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status, headers, config) {
$scope.commentaires.unshift(onecomment);
})
};
PHP文件:
<?php
$jsonString = file_get_contents('data/comment.json');
$data = json_decode($jsonString,true);
array_push( array('page' => 'essai', 'text' => 'essai2', 'author' => 'vince'));
$jsonData = json_encode($data);
file_put_contents('data/comment.json', $jsonData);
print_r($jsonData);
&GT;
控制台上的错误:
POST http://webtoutsaint.com/data/comment.php 500 (Internal Server Error) angular.js:8707
(anonymous function) angular.js:8707
sendReq angular.js:8501
$http.serverRequest angular.js:8221
wrappedCallback angular.js:11682
wrappedCallback angular.js:11682
(anonymous function) angular.js:11786
Scope.$eval angular.js:12946
Scope.$digest angular.js:12756
Scope.$apply angular.js:13050
(anonymous function) angular.js:20573
eventHandler
htaccess:
RewriteCond %{HTTP_HOST} ^www.webtoutsaint.com$ [NC]
RewriteRule ^(.*)$ http://webtoutsaint.com/$1 [R=301,L]
### If not already activated, activates the RewriteEngine module
RewriteEngine On
### If using a .htaccess file, uncomment the following line
Options +FollowSymLinks
### If the Host header is not correctly set
###RequestHeader set Host "api.seo4ajax.com"
### If a bot requests an escaped URL then proxify the request to SEO4Ajax
RewriteCond %{QUERY_STRING} _escaped_fragment_= [NC]
RewriteRule ^(.*)$ http://api.seo4ajax.com/5cdad99ad52efb8560de760adf13d862/$1 [P,QSA,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
RewriteRule .* index.html [L]
有人知道错误发生了什么吗?
答案 0 :(得分:1)
使用您发布的javascript,可以在服务器端检索数据:
$_POST['page'];
$_POST['text'];
$_POST['author'];
除非您还有其他未发布的代码
file_get_contents('data/comment.json');
$data = json_decode($jsonString,true);
如果出现,
将产生错误
1)data/comment.json
不能位于服务器文件系统上。
2)data/comment.json
不包含有效的json数据。
此外:
array_push( array('page' => 'essai', 'text' => 'essai2', 'author' => 'vince'));
会产生错误,因为需要两个参数:array_push