簡體   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