2016-05-21 192 views
0

你好,我有引发错误¿你可以告诉为什么一个非常基本的程序?Angularjs 500(内部服务器错误)

php的:基本上把在文件中的职位,是一个JSON。 这是一个长轮询系统的一部分。

<?php 
if(empty($_POST || !isset($_POST))) { 
    $last_ajax = null; 
} else { 
    $last_ajax = time(); 
} 
clearstatcache(); 
$last_change = filemtime('cache.txt'); 

if ($last_ajax == null || $last_change > $last_ajax) { 

    // Load the ajax 
    $R = json_decode(file_get_contents('php://input'), true); 
    // Load into memory the file 
    $F = json_decode(file_get_contents('cache.txt'), true); 
    // If not empty the file append 
    if(!empty($F)) { 
     $S = array_merge_recursive($F, $R); 
     file_put_contents('cache.txt', json_encode($S), true); 
    // Else just write into the file the post 
    } else { 
     file_put_contents('cache.txt', json_encode($R), true); 
    } 
    echo json_encode(file_get_contents('cache.txt'), true); 
    break; 
} 
?> 

而且在Angular中很简单。 这只是一个简单的POST发送到去上述数据PHP,这是一个JSON

var enrol = angular.module("enrol",[]); 

enrol.controller("enrolController", function($scope, $http){ 

    $scope.submit = function() { 
     console.log("Submitting"); 
     $http({ 
      method : "POST", 
      url  : "dependencies/cache.php", 
      data : { 
       'action': 'enrol', 
       'data': { 
        'Login': $scope.apliclogin, 
        'Password': $scope.aplicpass, 
        'rol': { 
         'admin': $scope.admin, 
         'sala': $scope.sala, 
         'barra': $scope.barra, 
         'cocina': $scope.cocina, 
         'caja': $scope.caja 
        } 
       } 
      }, 
      headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
     }).success(function(data){ 
      console.log(data); 
     }); 
    }; 
}); 
+0

有在parethesis一些失误,,,我固定的,仍然引发错误 – Gabriel

+0

休息时并不需要,我可以摆脱的代码它的一半工程从一开始在quiting脱如果,只是加载和写......我满了收到的档案,但仍然得到500错误 – Gabriel

+2

后的错误... – coatless

回答

0

我注意到的第一件事是你的PHP的第一道防线。难道你的意思是......

if(empty($_POST) || !isset($_POST)) { 
+0

其实我摆脱了代码的一半和轮询仍工作:新版本从加载ajax到休息之前回声。我仍然从投票方得到的数据..但由于某种原因抛出500 – Gabriel

+0

这真的很疯狂,但你知道它即使有错误哈哈!无论如何,我仍然会证明实现的问题 – Gabriel

+0

实际上重写代码,我不知道...重置所有的东西..所有浏览器和工作 – Gabriel