1

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 =(

1
  • create a plnkr/fiddle Commented Nov 12, 2013 at 0:57

1 Answer 1

1

You are not cancelling the form submission. The status zero is when the page is reloading because of the form submission.

Sign up to request clarification or add additional context in comments.

2 Comments

Same issue with ng-clik instead of form unfortunately.
You need to cancel the action. return false or preventDefault

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.