Reputation: 3490
can i ask can jquery ajax load method used to load an image, below is my code and it is fail, can anybody correct it?
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").ajaxStart(function(){
$(this).html("<img src='http://www.w3schools.com/jquery/demo_wait.gif' />");
});
$("button").click(function(){
$("div").load("http://www.google.com/images/logos/ps_logo2.png/");
});
});
</script>
</head>
<body>
<div><h2>Let AJAX change this text</h2></div>
<button>Change Content</button>
</body>
</html>
Upvotes: 0
Views: 1539
Reputation: 284796
No. Just create a img
element, set the src
, and place it where you wish.
$("div").empty().append($("<img/>", {src: "http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"}));
Upvotes: 3
Reputation: 53607
May be
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").ajaxStart(function(){
$(this).html("<img src='http://www.w3schools.com/jquery/demo_wait.gif' />");
});
$("button").click(function(){
$("div").html("<img src='http://www.w3schools.com/jquery/demo_wait.gif' />");
});
});
</script>
</head>
<body>
<div><h2>Let AJAX change this text</h2></div>
<button>Change Content</button>
</body>
</html>
Upvotes: 1