Div标签没有重新加载

时间:2016-07-09 04:36:25

标签: javascript jquery html css ajax

我正在尝试在数据库中有新内容时仅在页面上重新加载div标记

在Ajax中我测试新内容:

function adshandler() {
var d = new Date();
var cache = d.getTime();
$.getJSON("check_time.php?cache=" + cache, function(update) {
    if (update.count === true) {
        //location.reload();
        $('#slideshow').reload();
    }
}); 
} 
setInterval(adshandler, 10000);

div与ajax在同一页面上:

//Monday Afternoon
if ($dayofweek == "Monday" && $timeofday >= "12:00:00" && $timeofday <= "16:59:59"){
//Monday afternoon timeslot
echo "<div id='slideshow'>";
$stma= $conn->prepare("SELECT `Monday_Afternoon`
FROM `Client_Ads`");
$stma->execute();
while($resultst = $stma-> fetch()){
$mondayafternoonlist = $resultst["Monday_Afternoon"];
echo "<div class='slideshow'>";
echo "<img src='/$mondayafternoonlist'>";
echo "</div>";
}
echo "</div>";
}

div with a similarand, each one behind anand$('#slideshow').reload();个{if}} if if语句,具体取决于星期几等。

我的$('#slideshow').load();无效? 我也试过- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"showRecipeDetail" sender:[YOUR_ARRAY objectAtIndex:indexPath.row]]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"showRecipeDetail"]) { member_details *destViewController = segue.destinationViewController; destViewController.hello = sender; } }

2 个答案:

答案 0 :(得分:1)

&lt; p&gt;您可以使用&lt; code&gt; .load()&lt; / code&gt;来实现它。功能很少。以下是一个工作示例。&lt; / p&gt; &lt; pre&gt;&lt; code&gt;&lt; script src =&#34; https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"&gt;&lt; /脚本&GT; &LT;脚本&GT;     function changeDate(){         $(&#34;#d2p&#34;)。load(location.href +&#34;#d2&#34;);     } &LT; /脚本&GT; &lt; div id =&#34; d1p&#34;&gt;     &lt; div id =&#34; d1&#34;&gt;         &lt;?php echo date(&#34; H:i:s&#34;); ?&GT;     &LT; / DIV&GT; &LT; / DIV&GT; &LT; /代码&GT;&LT; /预&GT; &lt; p&gt;这是&lt; code&gt; DIV&lt; / code&gt;在此页面上部分点击按钮即可刷新。&lt; / p&gt; &lt; pre&gt;&lt; code&gt;&lt; div id =&#34; d2p&#34;&gt;     &lt; div id =&#34; d2&#34;&gt;         &lt;?php echo date(&#34; H:i:s&#34;); ?&GT;     &LT; / DIV&GT; &LT; / DIV&GT; &lt; button onclick =&#34; changeDate();&#34;&gt;更改日期&lt; / button&gt; &LT; /代码&GT;&LT; /预&GT; &lt; p&gt;这是演示&lt; a href =&#34; http://javascriptsolution.com/load-div-without-refreshing-entire-page/" rel =&#34; nofollow&#34;&gt;加载div而不刷新整个页面&lt; / a&gt;&lt; / p&gt;

答案 1 :(得分:0)

function adshandler() {
var d = new Date();
var cache = d.getTime();
$.getJSON("check_time.php?cache=" + cache, function(update) {
if (update.count === true) {
    //location.reload();
   $("#slideshow").load(location.href + " #slideshow");
}
}); 
} 
setInterval(adshandler, 10000);