Php 检测到中断的侦听器:拒绝中未提供配置对象:

Php 检测到中断的侦听器:拒绝中未提供配置对象:,php,angularjs,slim,Php,Angularjs,Slim,检测到中断的侦听器:拒绝中未提供配置对象: 当我调用post方法时,我得到了这个错误 我已经给出了服务、控制器和PHP代码 服务 angular.module('sbAdminApp') .factory('Branch', function($resource){ return $resource('api/branchdetails/:branch_id',{branch_id:'@_branch_id'},{ update: { method

检测到中断的侦听器:拒绝中未提供配置对象: 当我调用post方法时,我得到了这个错误

我已经给出了服务、控制器和PHP代码

服务

angular.module('sbAdminApp')
.factory('Branch', function($resource){
    return $resource('api/branchdetails/:branch_id',{branch_id:'@_branch_id'},{
        update: {
            method: 'PUT'
        }
     });
 })
.service('popupService',function($window){
    this.showPopup=function(message){
        return $window.confirm(message);
    }
});
控制器

angular.module('sbAdminApp')
.controller('BranchDetailsController', function($scope,$state,$stateParams,$window,Branch){

        $scope.branch = new Branch();

        $scope.addBranch=function(){                 
          $scope.branch.$save(function(){
              $state.go('branchdetails');
         });
    }
});
PHP代码

<?php

require_once('Slim/Slim.php');
require_once('dbconnection.php');

$app = new Slim();
$app->post('/branchdetails','addBranch');
$app->run();
function addBranch() {
    $request = Slim::getInstance()->request();
    $branch = json_decode($request->getBody());
    $sql = "INSERT INTO branch(branch_name, branch_address, branch_phno, branch_mobileno, branch_contactperson, branch_createdate, branch_modifieddate) VALUES (:branch_name,:branch_address, :branch_phno, :branch_mobileno, :branch_contactperson, :branch_createdate, :branch_modifieddate)";
    try {
        $db = getConnection();
        $stmt = $db->prepare($sql);  
        $stmt->bindParam("branch_name", $branch->branch_name);
        $stmt->bindParam("branch_address", $branch->branch_address);
        $stmt->bindParam("branch_phno", $branch->branch_phno);
        $stmt->bindParam("branch_mobileno", $branch->branch_mobileno);
        $stmt->bindParam("branch_contactperson", $branch->branch_contactperson);
        $stmt->bindParam("branch_createdate", $branch->branch_createdate);
        $stmt->bindParam("branch_modifieddate", $branch->branch_modifieddate);
        $stmt->execute();
        $branch->branch_id = $db->lastInsertId();
        $db = null;
        echo json_encode($branch); 
    } catch(PDOException $e) {

        echo '{"error":{"text":'. $e->getMessage() .'}}'; 
    }

}



?>

在代码中的某个地方,您有一个
拦截器
用于
$httpProvider
,该拦截器没有正确的响应错误部分,如下所示:

(function () {
    angular.module('App')               
           .config(['$httpProvider', httpProviderConfig]);

    function httpProviderConfig($httpProvider) {

        var interceptor = ['$rootScope', '$q', function ($rootScope, $q) {

            return {

                'responseError': function (rejection) {

                    return $q.reject(rejection);
                }
            };
        }];

        $httpProvider.interceptors.push(interceptor);
    }
})();

当api未返回有效的JSON时,通常也会发生这种类型的错误。如果内容类型头为application/JSON,或者响应看起来像有效的JSON字符串化对象或数组,AngularJS transform Response将尝试将响应解析为JSON。首先,始终尝试从后端接收有效的JSON对象,其次还要处理回调函数中的错误。这是一个很好的练习。如果仍然没有接收到有效的JSON,那么在错误回调中处理它也可以做到这一点

notificationsGET:function(){
返回Restangular.one('getusermenu.php')。获取({
菜单:“通知”,
令牌:sessionStorage.getItem('userToken')
}).then(功能(数据){
//成功回调
返回数据;
},函数(err){
//错误回调
log('error is',err);
}
);

}

即使我遇到了另一个类似“SyntaxError:Unexpected token S at Object.parse(native)”的错误,我并没有说保留拦截器,我说的是找到它,在所有角度文件中搜索
$httpProvider
,看看我什么时候被使用过?