Something strange is happening to me. This peculiar behavior occurs only on the initial POST request. However, when I resubmit the form, the subsequent requests work perfectly fine.
The first $http post call leads to the error function in .then, even though the backend call to the server successfully completes end-to-end (status -1). If I redo the same request, it smoothly goes through the success path in .then.
In my application, I am utilizing Angular's ng-view, ng-route, and ng-controller constructs to connect everything.
Thank you for your assistance.
$http({
url: "/api/v1/login",
method: "POST",
headers: { "Content-Type": "application/json" },
data: {
username: uname,
password: pword
}
})
.then (
function (success) {
$scope.content = success.data;
if ($scope.content.status == "Login successful") {
window.location.href="/apps/home.html";
} else {
alert("Login failed");
window.location.href="#login";
};
},
function (error) {
alert("Call error = " + error.status);
window.location.href="#login";
}
);