Chrome/Firefox 上的 $http JSONP 请求结果为 404,在 IE 中正常工作
$http JSONP request results in 404 on Chrome/Firefox, works correctly in IE
我正在使用 random word API 开发一个简单的 Hangman 应用程序。作者说它是 JSONP 兼容的。
看到这个Fiddle: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(
"");
});
}
您是否运行将您的代码放在 HTTPS 页面上?因为这似乎是一个 mixed content page 问题。我在 Chrome 和 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.
当您尝试从 HTTPS 页面加载 HTTP 页面时会发生这种情况。你可以看到,如果你 运行 来自 http://jsfiddle.net/1t8ur23p/7/ 的代码(http,而不是 https),它工作正常。
我正在使用 random word API 开发一个简单的 Hangman 应用程序。作者说它是 JSONP 兼容的。
看到这个Fiddle: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(
"");
});
}
您是否运行将您的代码放在 HTTPS 页面上?因为这似乎是一个 mixed content page 问题。我在 Chrome 和 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.
当您尝试从 HTTPS 页面加载 HTTP 页面时会发生这种情况。你可以看到,如果你 运行 来自 http://jsfiddle.net/1t8ur23p/7/ 的代码(http,而不是 https),它工作正常。