繁体   English   中英

$ http JSONP请求在Chrome / Firefox上获得404,在IE中正常运行

[英]$http JSONP request results in 404 on Chrome/Firefox, works correctly in IE

我正在使用随机单词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(
          "");
  });
}

您是否在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://jsfiddle.net/1t8ur23p/7/(http ,而不是https)运行代码,它可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM