I'm trying to make update div block after jQuery ajax succesfull request, this is works but all blocks dublicates (picture1), in picture 2 is shown how it looks after refreshing page with browser.
To update block I'm using function:
function async_get(addr,func) {
$.ajax({
url: addr,
async: false,
success: func
});
}
and it's called like this:
async_get(
'http://localhost/getfreelance/welcome',
function (data) {
$('#header').html(data);
}
);
Any solutions? :)
Picture 1: http://postimage.org/image/uxghnpgfb/
Picture 2: http://postimage.org/image/wj0v02md7/
You didn't understand, i need to update/refresh div block when ajax request is success, instead of your function fffsuccess() i'm using: 'function async_get(addr,func) { $.ajax({ url: addr, async: false, success: func }); }'
and my #header div updates but it dublicates data.
html:
<div id="YourImgDivID"></div>
function:
function fffsuccess(){
alert('success!');
$("#YourImgDivID").html('<img src="image1.png">');
}
function ffferror(){
alert('error!');
$("#YourImgDivID").html('<img src="image2.png">');
}
use:
$.ajax({
url: 'ajax.cos.php',
type: 'post',
async: false,
success: fffsuccess,
error: ffferror
});
P.S. you can replace
$("#YourImgDivID").html('<img src="image2.png">');
to:
$("#YourImgDivID img").attr('src', 'image2.png');
or
html to:
<div id="YourImgDivID"><img id="YourImgID" src="image105.png"></div>
jQuery to:
$("#YourImgDivID img#YourImgID").attr('src', 'image2.png');
whatever