FreeCodeCampでランダムクォートジェネレータを完了しようとしています。私はかなり持っていますが、私はもう一歩進んでボタンの背景画像を変更したいと決めました。バックグラウンドimgが最初に設定された最初の呼び出しからバックグラウンドimgがキャッシュされていると思います。そのため、私がボタンをクリックするたびに、ブラウザは本質的にサイトを再訪して新しいimgを引っ張る代わりに、キャッシュされたimgを再ロードしています。jQueryでのキャッシングからの画像の停止
私が使用しているソースは、訪問ごとに異なるイメージを返すサイトです。
私はURLの最後にタイムスタンプを追加しようとしましたが、サイトは無効なアドレスイメージを投げてしまいました。
<html>
<head>
</head>
<body>
<div class="container-fluid" id="mainDiv">
<div class = "row text-center">
<div class = "col-xs-12 well" id = "quote">
The quote will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getQuote" class = "btn btn-primary">
Get Quote
</button>
</div>
</div>
</div>
</body>
</html>
body{
background-image: ;
}
#mainDiv{
margin: 0 auto;
max-width: 400px;
margin-top: 200px;
}
$(document).ready(function(){
$('body').css('background-image', 'url("https://source.unsplash.com/random")');
$.getJSON("http://quotes.stormconsultancy.co.uk/random.json", function(json){
$("#quote").html('"' +json.quote + '"<br> - ' + json.author);
});
$("#getQuote").on("click", function(){
$('body').css('background-image', 'url("https://source.unsplash.com/random")');
$.getJSON("http://quotes.stormconsultancy.co.uk/random.json", function(json){
$("#quote").html('"' +json.quote + '"<br> - ' + json.author);
});
});
});