jsonp does not work with ionic

0

How about, I've been working on ionic jsonp for about 5 days and the case is that with angularjs it works and with jquery too but when I use jsonp with ionic I can not make it work and it always returns error, here I share my code

app.js

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.config(['$sceDelegateProvider', function($sceDelegateProvider) {
  // We must whitelist the JSONP endpoint that we are using to show that we trust it
  $sceDelegateProvider.resourceUrlWhitelist([
    'self',
    'http://*/**'
  ]);
}])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }

  });
})

.controller("movies",function($scope,$http, $rootScope, $ionicPlatform) {
    $ionicPlatform.ready(function() {
      $scope.items = [];

      var url = 'http://127.0.0.1/llantas/index.php';
      $http.jsonp(url,{name:'texto'}).
      then(function(response) {
          console.log('entra');
        }, function(response) {
          console.log(response['data']+'-'+response['status']);
      });
    });
});

index.php

<?php
$user     = $_GET['name'];
$arr = array('consulta' => "$user");
$enc = json_encode($arr);
//header('Content-Type: application/json;');
echo($enc);
?>

When I try to get an answer with ajax everything works perfectly, I have what I sent as an answer but when I try it from the code that I have in ionic it does not work and I have tried it in several ways like

$ http ({method, url, data: {})

and I still get an error which is undefined-404

that comes from the following line console.log (response ['data'] + '-' + response ['status']);

It does not occur to me that it may be happening, I have seen all the answers from Google and the stackoverflow forum in English and in Spanish and I can not solve this problem, another thing to say is that by using the browser, putting the url localhost: 8080 / tires / index.php? name = text I also get the expected response Where is the error?

    
asked by Francisco 18.12.2016 в 18:52
source

1 answer

0

You can try this way:

var url = 'http://127.0.0.1/llantas/index.php';
  $http.get(url,{name:'texto'}).
  then(function(response) {
      console.log('entra');
    }, function(response) {
      console.log(response['data']+'-'+response['status']);
  });
}
    
answered by 24.12.2016 в 14:21