[英]$http JSONP request results in 404 on Chrome/Firefox, works correctly in IE
I'm developing a simple Hangman application using the random word API . 我正在使用随机单词API开发一个简单的Hangman应用程序。 The author says that it's JSONP compatible.
作者说它与JSONP兼容。
See this Fiddle: https://jsfiddle.net/1t8ur23p/7/ 看到这个小提琴: https : //jsfiddle.net/1t8ur23p/7/
The relevant code is here. 相关代码在这里。 This is working correctly in IE and I'm getting a random word every time.
这在IE中正常工作,我每次都会得到一个随机单词。 But I'm getting a 404 in Firefox and Chrome and I can't tell why.
但是我在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(
"");
});
}
Are you running your code on a HTTPS page? 您是否在HTTPS页面上运行代码? Because this seems to be a mixed content page issue.
因为这似乎是一个混合内容页面问题。 I'm seeing the following error on Chrome and Firefox:
我在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.
This happens when you try to load a HTTP page from a HTTPS page. 当您尝试从HTTPS页面加载HTTP页面时会发生这种情况。 You can see that if you run the code from http://jsfiddle.net/1t8ur23p/7/ (http, not https), it works fine.
你可以看到,如果你从http://jsfiddle.net/1t8ur23p/7/(http ,而不是https)运行代码,它可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.