2016-07-18 5 views
0

현재 codepen.io로 작은 임의 견적 생성기 (Freecodecamp Project)를 진행 중입니다. 당신은 여기에서 찾을 수 있습니다 : 나는 마이크로 소프트 엣지있는 페이지를 열면 http://codepen.io/Baumo/pen/VjQbBj?editors=1000getJson은 Google 크롬에서만 1 회만 작동합니다.

<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
</head> 

<script> 
    $(document).ready(function(e){ 
     $('#getQuote').click(function(){ 
     $.ajax({ 
      dataType: "json", 
      url: 'http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1', 
      success: function(a) { 
      $(".quote").html(a[0].content + "<p>&mdash; " + a[0].title + "</p>"); 
      } 
     }); 
    }); 
    }); 
</script> 

<body> 
    <div class="box"> 
    <div class="message quote"> 

    </div> 
    <div class = "right"> 
     <button class="btn" id="getQuote"> 
     NEW QUOTE 
     </button> 
    </div> 
    </div> 
</body> 

, 그것은 잘 작동합니다. 그러나 Google 크롬에서 "New Quote"버튼은 처음 클릭 할 때만 작동합니다.

이 문제를 해결하는 방법은 무엇입니까?

감사합니다.

답변

0

크롬이 적극적으로 아약스 요청을 캐싱하고 있습니다. 요청에 cache: false을 추가하십시오.

$.ajax({ 
     dataType: "json", 
     url: 'http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1', 
     cache: false, 
     success: function(a) { 
     $(".quote").html(a[0].content + "<p>&mdash; " + a[0].title + "</p>"); 
     } 
    }); 
관련 문제