Que tal, llevo unos 5 dias intentando hacer funcionar en ionic jsonp y el caso es que con angularjs funciona y con jquery tambien pero cuando utilizo jsonp con ionic no logro hacer que funcione y siempre me devuelve error, aqui os comparto mi codigo
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);
?>
Cuando intento obtener una respuesta con ajax todo funciona perfectamente, tengo como respuesta lo que le envio pero cuando lo intento desde el código que tengo en ionic no funciona y he probado de varias maneras como
$http({method,url,data:{})
y sigo obteniento un error el cual es undefined-404
que viene de la siguiente linea console.log(response['data']+'-'+response['status']);
Ya no se me ocurre que puede estar pasando, he visto todas las respuesta de google y de el foro stackoverflow en ingles i en español y no logro solucionar este problemas, otra cosa a decir es que mediante el navegador poniendo la url localhost:8080/llantas/index.php?name=texto tambien obtengo la respuesta esperada ¿donde está el error?