Unable to get my Json service

Newbie in ionic.
unable to get my php service… here’s my test code
Thank’s for help

angular.module(‘starter.services’, [])

.factory(‘Chats’, function($http) {
// Might use a resource here that returns a JSON array

var url = "http://envieslocales.fr/testws5.php/?s=7";
var chats = $http.get(url);

return {
all: function() {
return chats;
remove: function(chat) {
chats.splice(chats.indexOf(chat), 1);
get: function(chatId) {
for (var i = 0; i < chats.length; i++) {
if (chats[i].id === parseInt(chatId)) {
return chats[i];
return null;

use JSONP , other wise you need to open the Access-Control-Allow-Origin on your server

thank’s a lot.
I ve searched a lot but don’t manage to use jsonp…
can you bring me example please?

I’ve tried this

url = ‘http://envieslocales.fr/testws5.php/?s=7&callback=JSON_CALLBACK’;
var chats = response;

and nothing works…

what is the output of the console ?

use chrome console to get the output error and put it here, without more information no one can answer you

return data as a JSON

                 $result = mysql_query( "select * from chat");
                 $data = array();

		while ($row = mysql_fetch_assoc($result)) {
		   $data[] = $row;
		echo json_encode($data);

                  // your service javascript
                 this.request("chat.php", params, function (res) {
                     var result = JSON.parse(JSON.stringify(res));

Thank’s for help, I’ve found my pb…
the controller refresh the view BEFORE the service has done the $http…
that was my pb, I’ve solved with a resolve in my app.js