繁体   English   中英

$ http.post到php文件,500内部服务器错误

[英]$http.post to php file, 500 internal server error

我正在尝试将一些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);

?>

控制台上的错误:

     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]

有人知道发生了什么错误吗?

使用您发布的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM