Javascript $http JSONP请求在Chrome/Firefox上生成404,在IE中正常工作
我正在使用开发一个简单的Hangman应用程序。作者说它与JSONP兼容 看这把小提琴: 相关代码在这里。这在IE中正常工作,每次我都会收到一个随机单词。但我在Firefox和Chrome上得到了404,我不知道为什么Javascript $http JSONP请求在Chrome/Firefox上生成404,在IE中正常工作,javascript,angularjs,jsonp,Javascript,Angularjs,Jsonp,我正在使用开发一个简单的Hangman应用程序。作者说它与JSONP兼容 看这把小提琴: 相关代码在这里。这在IE中正常工作,每次我都会收到一个随机单词。但我在Firefox和Chrome上得到了404,我不知道为什么 function getSecretWord() { //call the random word API using JSONP request $http.jsonp( 'http://randomword.setgetgo.com/get.php?cal
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页面上运行代码?因为这似乎是个问题。我在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,而不是https)运行代码,它工作正常。您是在https页面上运行代码吗?因为这似乎是个问题。我在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,而不是https)运行代码,它可以正常工作。Ahh。。。就是这样。啊。。。就这样。