Why doesn't my HTTP get work on pull to refresh?


#1

Hi guys,
I’m trying to get my HTTP.get to work on my pull to refresh. It’s having trouble receiving items from the url. I’ll place all my code related to my HTTP below. If anyone could help me out i would be very grateful. Thanks.

Code:

Tab-accouncements.html:

<html ng-app="ionicApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <title>Ionic Pull to Refresh</title>

    <link href="http//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
    <script src="http//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
    <script src="js/controllers.js"></script>
    
  </head>
  <body ng-controller="MyCtrl">
  
    <ion-header-bar class="bar-positive">
      <h1 class="title">Pull To Refresh</h1>
    </ion-header-bar>
	<ion-view view-title="Announcements">
    <ion-content>
      <ion-refresher on-refresh="doRefresh()">
                     
      </ion-refresher>
      <ion-list>
        <ion-item ng-repeat="item in items">{{announcement_name}} {{date}} {{message}}</ion-item>
      </ion-list>
    </ion-content>
    </ion-view>

  </body>
</html>

controller.js:

angular.module('myApp', ['ionic'])

    .controller('MyCtrl', function($scope, $http) {
      $scope.items = [1,2,3];
      $scope.doRefresh = function() {
        $http.get('http://www.wikicode.co.uk/announcement')
         .success(function(newItems) {
           $scope.announcement_name = newItems.announcement_name;
           $scope.date = newItems.date;
           $scope.message = newItems.message;
         })
         .finally(function() {
           // Stop the ion-refresher from spinning
           $scope.$broadcast('scroll.refreshComplete');
         });
         myApp.error(function(newItems) {
    		alert("something went wrong");
    	})
      };
    });

Link:

http://www.wikicode.co.uk/announcement



  { 
    	"announcement_name": "Testing"
    	"date": "16/05/2015"
    	"message": "Test"
    }

#2

Have you seen this post?


#3

Hi,
I’ve got some news. It’s really odd. The HTTP Get will work when i’m running it via the ionic app. ‘Ionic upload’ but won’t work when i’m running it on my computer via the web browser or when i download the application onto my phone. Very strange. Any idea why?? I’ve done what it says on that website link and i still get the same results.


#4

If you’re running in Chrome, you should be able to bring up the developer console and see the requests/responses under the Network tab.


#5

Thanks for the response. I found out that the issue was because i needed to import some permissions into my android application.


#6

Can you tell us, which permissions you added and what went wrong?
thanks in advance


#7

These are all the permission I’ve added

 <uses-permission android:name="android.permission.INTERNET" /> 
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
  <uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" /> 
  <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />