Load script after Ajax request
(Sorry for my bad English)
I have the following HTML code:
<div id='ad_fulldiv'>
//Some text and images
<div id='ad_content''>
require_once('/include/adcontent.inc.php');
</div>
</div>
I have also a Jquery code with Ajax request. In the file adcontent.inc.php there is a switch loop which echoes random content what depends on the content in a database. After the user clicks on a button a Ajax request is called which updates the database. If the file returns 'true' (update is successfull) the div ad_content should fadeout en should be reloaded with adcontent.inc.php. It should have other content now, because the Database is updates.
But how can I reload the div? I think the lo开发者_StackOverflow社区ad option doesnt work. I tried to do that, but exactly the same content is loaded.
Why not have your includes/adcontent.inc.php script return the div content rather than true/false?
$.ajax({
url: 'includes/adcontent.inc.php',
cache: false,
beforeSend: function (data) {
$('#ad_content').html("Loading...");
},
success: function (data) {
if (data!='error'){
$('#ad_content').html(data);
}else{
$('#ad_content').html("<span style='color:red;'>Error!</span>");
}
},
error: function (data) {
$('#ad_content').html("<span class='error'>Error!</span>");
}
});
精彩评论