2016-05-26 5 views
1

Ich entwickle eine einfache Henker-Anwendung mit der random word API. Der Autor sagt, dass es JSONP-kompatibel ist.

Sehen Sie diese Fiddle: https://jsfiddle.net/1t8ur23p/7/

Der entsprechende Code ist hier. Dies funktioniert im IE korrekt und ich bekomme jedes Mal ein zufälliges Wort. Aber ich bekomme eine 404 in Firefox und Chrome und ich kann nicht sagen warum.

function getSecretWord() { 
    //call the random word API using JSONP request 
    $http.jsonp(
     'http://randomword.setgetgo.com/get.php?callback=JSON_CALLBACK' 
).then(function(response) { 
     console.log(response); 
     //apply the random word to the local secret word 
     $scope.word = response.data.Word; 
     //setup the other parts of the game 
     $scope.letters = response.data.Word.split(""); 
     $scope.answerArray = response.data.Word.replace(/./g, '-') 
      .split(""); 
    }).catch(function(response) { 

     //debugging... see the contents of the faulty response 
     $scope.error = response; 

     //there's been an error, just default the word to 'hello' 
     $scope.word = 'hello'; 
     $scope.letters = $scope.word.split(""); 
     $scope.answerArray = $scope.word.replace(/./g, '-').split(
      ""); 
    }); 
} 

Antwort

0

Führen Sie Ihren Code auf einer HTTPS-Seite aus? Denn das scheint ein mixed content page Problem zu sein. Ich sehe die folgenden Fehler auf Chrome und Firefox:

Mixed Content: The page at 'https://fiddle.jshell.net/1t8ur23p/7/show/' was loaded over HTTPS, but requested an insecure script 'http://randomword.setgetgo.com/get.php?callback=angular.callbacks._0'. This request has been blocked; the content must be served over HTTPS. 

Dies geschieht, wenn Sie versuchen, eine HTTP-Seite von einer HTTPS-Seite zu laden. Sie können sehen, dass, wenn Sie den Code von http://jsfiddle.net/1t8ur23p/7/ (http, nicht HTTPS) ausführen, es funktioniert.

+0

Ahh ... das war es. – Kyle