这就是我工厂里的东西。当我从控制器以常规的ajax语法运行它时,这工作正常。
function endAgentSession(sessionData, tokenData) {
var sessionId = sessionData.data.sessionId,
access_token = tokenData.access_token,
baseURI = tokenData.resource_server_base_uri,
endAgentSessionPayload = {
'sessionId': sessionId,
'forceLogOff': true,
'endContacts': true,
'ignorePersonalQueue': false
};
console.log(sessionId, "sessID");
return $http({
'url': baseURI + 'services/v6.0/agent-sessions/' + sessionId,
'type': 'DELETE',
'headers': {
//Use access_token previously retrieved from inContact token service
'Authorization': 'bearer ' + access_token,
'content-Type': 'application/json'
},
'data': endAgentSessionPayload
}).then(function(res){
return res })};
}
这是我的控制器。当我通过ng-click从控制器调用endAgentSession函数时,错误输出到405 ..
$scope.endAgentSession = function(){
agentFactory.endAgentSession($scope.sessionData, $scope.tokenData);
};
我做错了什么?它在控制器中与ajax一起工作,然后当我把它移到工厂并使用了一个承诺时似乎打破了。
它实际上正在显示它'在网络中请求GET请求.. [![在此处输入图像说明] [1]] [1]
完全控制器:
csMgmtApp.controller('launchedController', ['$scope', '$http', '$document', '$resource', 'agentFactory', '$timeout', function ($scope, $http, $document, $resource, agentFactory, $timeout) {
$scope.agentStatePayload = {};
$scope.sessionData = {};
$scope.tokenData = {};
$scope.startSessionPayload = {
'stationPhoneNumber': '2223222222',
'inactivityTimeout': 0,
'inactivityForceLogout': 'false'
};
$document.ready(function () {
$scope.tokenData = agentFactory.getToken();
console.log($scope.tokenData);
});
agentFactory.startSession($scope.startSessionPayload, $scope.tokenData).then(function(res){
console.log("sessionId", res);
$scope.sessionData = res;
});
$scope.endAgentSession = function(){
agentFactory.endAgentSession($scope.sessionData, $scope.tokenData);
};
}]);
这一切似乎都在起作用,除了endSession,现在......
答案 0 :(得分:0)
我应该猜到每次你说
来自控制器的常规ajax语法
你的意思是你以前使用过jQuery $connect = mysqli_connect("localhost", "root", "", "aid");
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_assoc($result)) {
if ($row['username'] == $username && $row['password'] == $password) {
header("Location: incedent-form.php");
} else{
header("Location: login-form.php");
}
}
} else {
header("Location: login-form.php");
}
。
不同之处在于,在Angular $.ajax
中设置请求方法的属性是$http
,而不是method
。
您可以使用
进一步简化它type