[英]angular $http is returning status 0
I am using angular 1.0.7 我正在使用角度1.0.7
Here is my HTML: 这是我的HTML:
<section id="mcslsearch" ng-controller="McslSearchCtrl">
<div id="search_wrapper">
<form role="search" id="search_form" ng-submit "performSearch()">
<input type="text" placeholder="Search For A Style Of Music" ng-model="search" value="" name="search" id="search_text">
<button class="icon" id="search"></button>
<div class="icon" id="search_hover"></div>
</form>
</div>
</section>
and my js code: 和我的js代码:
McslApp.controller('McslSearchCtrl', function McslSearchCtrl($scope, $http) {
$scope.search = '';
$scope.performSearch = function () {
var search = $scope.search,
url = "a_http://blabla_that_returns_JSON",
$http({method: 'GET', url: url}).
success(function(data, status) {
alert("good");
}).
error(function(data, status) {
alert("bad status = "+status);
});
};
});
McslApp is the app that englobes everything (in the tag). McslApp是一款包含所有内容(在标签中)的应用程序。
Does someone see what the problem is here? 有人看到这里的问题了吗? I tried the shortcut version as well, not better.
我也尝试了快捷方式版本,不是更好。 Alerts "bad status = 0".
警报“不良状态= 0”。 Is that the fact that I use ng-submit?
那是我使用ng-submit的事实吗?
This seems so similar to http://docs.angularjs.org/api/ng .$http#methods_get to me... any suggestions welcome! 这似乎与http://docs.angularjs.org/api/ng非常相似。$ http#methods_get给我...欢迎任何建议! I'm stuck with that for a good hour now....
我已经坚持了一个小时。
EDIT: 编辑:
So apparently the form bit is not what I want, so I tried this in HTML instead: 因此,显然表单不是我想要的,所以我在HTML中尝试了此操作:
<section id="mcslsearch" ng-controller="McslSearchCtrl">
<div id="search_wrapper">
<input type="text" placeholder="Search For A Style Of Music" ng-model="search" value="" name="search" id="search_text">
<button ng-click="performSearch()" class="icon" id="search"></button>
<div class="icon" id="search_hover"></div>
</div>
</section>
with an ng-click but same problem. 用ng键单击,但有相同的问题。 Calls the JS code but returns status 0 =(
调用JS代码,但返回状态0 =(
You are not cancelling the form submission. 您不会取消表单提交。 The status zero is when the page is reloading because of the form submission.
状态为零是由于提交表单而重新加载页面时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.