title: Ionic, PHP, MySQL and JSONP with Angular
body: <p>I was trying to get the parameter from my php page to android app,</p>
  
  <p>here the code on <strong>js.php</strong></p>
  
  <pre><code>&lt;?php header('content-type: application/json; charset=utf-8');
  $rest=$_GET['rest'];
  
  if ($rest=="query"){
  $sql = "SELECT * FROM post";
  $result = $conn-&gt;query($sql);
  
  $emparray = array();
      while($row =mysqli_fetch_assoc($result))
      {
          $emparray['posts'] = $post;
          $post[] = str_replace('"', "'", $row);
      }
      $json = json_encode($emparray);
  
  echo isset($_GET['callback'])
      ? "{$_GET['callback']}($json)"
      : $json;
  }
  ?&gt;
  </code></pre>
  
  <p>and I'm using <strong>.htaccess</strong> on my server</p>
  
  <pre><code>RewriteEngine On
  Options +FollowSymLinks -MultiViews
  RewriteRule    ^rest/([A-Za-z]+)/?$    js.php?rest=$1    [NC,L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^([^\.]+)$ $1.php [NC,L]
  
  RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
  RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 
  </code></pre>
  
  <p>and last, my js on ionic <strong>www\js\app.js</strong></p>
  
  <pre><code>var App = angular.module('App', ['ionic']);
  
  
  App.service("Robo", ["$http", "$log", Robo])
  App.controller("AppCtrl", ["$scope", "Robo", "$log", AppCtrl]);
  
  
  function AppCtrl($scope, Robo, $log){
      $scope.posts = [];
      $scope.refresh = function(){
          Robo.getBlogs($scope);
      }
  } 
     function Robo($http, $log) {
          this.getBlogs = function($scope){
                  $http.jsonp("http://www.domain.com/rest/query?callback=JSON_CALLBACK")
                      .success(function(result){
                          $scope.posts = result.posts;
                          $scope.$broadcast("scroll.refreshComplete");
                      });
          }
      }
  </code></pre>
  
  <p>on index.html</p>
  
  <pre><code>&lt;html lang="en" data-ng-app="App"&gt;
  &lt;ion-content&gt;
                  &lt;ion-refresher on-refresh="refresh()"&gt;&lt;/ion-refresher&gt;
                  &lt;div data-ng-show="!posts.length"&gt;
                      &lt;br&gt;&lt;br&gt;
                      &lt;center&gt;
                          &lt;h1&gt;Pull to Refresh&lt;/h1&gt;
                      &lt;/center&gt;
                  &lt;/div&gt;
  .
  .
  .
  </code></pre>
  
  <p>I'm stuck here with no data on array $scope.posts, so when I pull the refresh, the loading never end. please kindly help and suggest me to solve this issue</p>