のindex.html:イメージをJSONに保存するにはどうすればよいですか?
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ajax</title>
</head>
<body>
<h2>jQuery AJAX (open in Firefox)</h2>
<h3> Get partial page content using:</h3>
<button id="btnAjax" > .ajax() REST</button>
<button id="btnLoadText">.load() Text File</button>
<h2> Result</h2>
<div id="showResult"></div>
<div> <img id="i1"> </div>
<hr>
<a href="https://oscarotero.com/jquery/">jQuery Quick API Reference at https://oscarotero.com/jquery/</a>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="ajax.js"></script>
</body>
</html>
ajax.js:
$('#btnLoadText').click(function() { $("#showResult").load("show.txt"); });
$('#btnAjax').click(function() { callRestAPI() });
// Perform an asynchronous HTTP (Ajax) API request.
function callRestAPI() {
var root = 'https://jsonplaceholder.typicode.com';
$.ajax({
url: root + '/photos/6',
method: 'GET'
}).then(function (response) {
console.log(response);
$('#i1').attr("src", response.url);
$('#showResult').html(response.body);
});
}
})(jQuery);
私はdivタグのIDを使って試してみました。しかし、私は画像を表示されませんでした。 画像タグを使用せずに画像を読み込む別の方法を教えてもらえますか?
あなたはあなたの質問について明白にする必要があります。ATMには別の質問があります.... –