【发布时间】:2016-09-24 21:22:16
【问题描述】:
我正在使用 random word API 开发一个简单的 Hangman 应用程序。作者说它是 JSONP 兼容的。
看到这个小提琴:https://jsfiddle.net/1t8ur23p/7/
相关代码在这里。这在 IE 中正常工作,我每次都会得到一个随机词。但是我在 Firefox 和 Chrome 中得到了 404,我不知道为什么。
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(
"");
});
}
【问题讨论】:
标签: javascript angularjs jsonp