Javascript $http在Angularjs 1.x中不起作用
我被angular的所有类型的$http请求困住了。我试图用$http访问rest API,但我的代码在其中运行,并且没有在chrome网络选项卡中显示任何调用。我正在使用python simplehttpserver执行项目 下面是我试图点击的服务代码 HTML代码Javascript $http在Angularjs 1.x中不起作用,javascript,angularjs,ajax,http,Javascript,Angularjs,Ajax,Http,我被angular的所有类型的$http请求困住了。我试图用$http访问rest API,但我的代码在其中运行,并且没有在chrome网络选项卡中显示任何调用。我正在使用python simplehttpserver执行项目 下面是我试图点击的服务代码 HTML代码 <form class="form-horizontal" method="post" ng-submit="loginModel.login()"> <div class="form-
<form class="form-horizontal" method="post" ng-submit="loginModel.login()">
<div class="form-group">
<div class="col-md-12">
<input type="text" class="form-control" placeholder="Username" ng-model="loginModel.username"/>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="password" class="form-control" placeholder="Password" ng-model="loginModel.password"/>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<a href="#" class="btn btn-link btn-block">Forgot your password?</a>
</div>
<div class="col-md-6">
<button type="submit" class="btn btn-info btn-block">Log In</button>
</div>
</div>
</form>
我已经在我的控制器中注入了$http,并尝试使用$resource点击API,但当我点击服务点击事件时,什么都没有发生
我已经用核心javascript尝试过了,它运行得很好,但为什么它不能运行$http或$resource呢
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://www.example.com/", false);
xhr.send();
console.log(xhr.status);
请帮我做这个
谢谢看起来您的URL格式不正确,如果出现错误,您也不会做任何事情
$http({
method: 'POST',
url:'http://example.com',
data:userDetail,
}).then(function (response) {
console.log(response)
}, function (response) {
console.log('error response', response);
});
如果出现错误,这至少会在控制台中显示一些内容
$http({
method: 'POST',
url:'http://example.com',
data:userDetail,
}).then(function (response) {
console.log(response)
}, function (response) {
console.log('error response', response);
});
如果url更改仍然不起作用,请检查浏览器开发人员控制台的“网络”选项卡,查看是否发出请求,如果发出请求,是否超时(卡在挂起状态)在哪里注入
$http
?现在请看问题,我已经包括了控制器依赖项标题。您在XMLHttpRequest中使用了GET方法,在$http中使用了POST方法。您需要使用GET吗?我需要同时使用这两种方法,但没有任何类型的请求正在访问服务器您的$http
中的url
格式也很奇怪。尝试使用https://www.example.com/
正如您在XMLHttpRequest中所做的那样。问题不是来自网络调用,而是来自开始调用未进入顶层服务器错误事件,当http命中服务器并在响应状态下获取响应时。