Reputation: 996
I want to use $.ajax
to get any picture from a URL and show it on the page.
It should happen when button is clicked.
$(document).ready( function() {
$("button").click(function(){
$.ajax({url: "index.html", success: function(result){
$("#image").attr("src","test.png");
}});
});
});
HTML Code:
<button type = "button">Click Me</button>
<div>
<img id = "image" src = ""/>
</div>
Upvotes: 0
Views: 1732
Reputation: 996
This works fine. But still I need to use a localserver to run this without the console error mentioned in edit.
$(document).ready( function() {
$("button").click(function(){
var url = 'test.png';
$.ajax({
url : url,
cache: true,
processData : false,
}).always(function(){
$("#image").attr("src", url);
});
});
});
Upvotes: 0