Bonjour à tous,
je développe une application avec angularJS, et une requête get est pas très gentille avec moi, voilà le code du service:
Quand j'exécute tout ça dans mon application, j'ai l'erreur 'Impossible to get en language.' qui s'affiche deux fois en alert, pourtant, quand je vais dans la console, j'ai:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 app.service('languageModel', function($http, $q){ * ****// Service pour recupérer la langue stocké en localStorage ****// Et recuperer le fichier .json de la langue ****// Pour le retourner ****$this = this, * ****$this.language = {}, * * ****$this.getLanguage = function(){ ********return $this.language; ****}, * ****// Méthodes qui s'occupe de charger le fichier .json ****$this.setLanguage = function(){ ********deferred = $q.defer(), ********lang = (localStorage.getItem('lang')) ? localStorage.getItem('lang') : "en"; ********// Requete pour recuperer le fichier .json ********$http.get('lang/'+lang+'.json') ************// Succés de la requete ************.success(function(data, status){ ****************$this.language = data; ****************deferred.resolve($this.language); ************}) ************// Echec de la requete ************.error(function(data, status){ ****************deferred.reject('Impossible to get '+lang+' language.'); ************}); * ********// On retourne la promesse ********return deferred.promise; ****} })
Voilà le controller qui gère le service et tout:XHR finished loading: GET "http://localhost:8080/app/www/en.json".
Et une dernière petite erreur dans la console, que je n'arrive pas à localisé (l'erreur est localisé par la console dans le framework angular.js):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 app.controller('menuCtrl', function($scope, languageModel){ ****$scope.loading = true; ****$scope.language = languageModel.setLanguage().then(function(language){ ********$scope.loading = false; ********$scope.language = language; ****}, function(msg){ ********alert(msg); ****}); })
Voilà tout, merci d'avance à tout ceux qui m'aideront.SyntaxError: Unexpected token /
****at Object.parse (native)
****at fc (http://localhost:8080/app/www/libs/angular.js:14:304)
****at e.defaults.transformResponse (http://localhost:8080/app/www/libs/angular.js:71:4)
****at http://localhost:8080/app/www/libs/angular.js:70:274
****at q (http://localhost:8080/app/www/libs/angular.js:7:296)
****at Ic (http://localhost:8080/app/www/libs/angular.js:70:256)
****at b (http://localhost:8080/app/www/libs/angular.js:71:464)
****at w (http://localhost:8080/app/www/libs/angular.js:100:398)
****at http://localhost:8080/app/www/libs/angular.js:102:64
****at g.$eval (http://localhost:8080/app/www/libs/angular.js:113:390)
Partager