Reputation: 405
I am using angular 1.0.7
Here is my 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:
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).
Does someone see what the problem is here? I tried the shortcut version as well, not better. Alerts "bad status = 0". Is that the fact that I use ng-submit?
This seems so similar to http://docs.angularjs.org/api/ng.$http#methods_get to me... any suggestions welcome! 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:
<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. Calls the JS code but returns status 0 =(
Upvotes: 1
Views: 343
Reputation: 207501
You are not cancelling the form submission. The status zero is when the page is reloading because of the form submission.
Upvotes: 1