我搜索的一些帖子表明问题存在于jquery处理的ajax中。我测试了删除所有ajax调用,并通过使用$ ajaxSetup({cache:true})和其他方法跟踪其他帖子的建议,但没有一个工作。我也尝试完全删除jquery库或我的脚本。并且无限循环的get请求已停止。
问题似乎存在于这段代码中,其中all_posts [j] [0]是重新插入文档的div元素。我尝试在追加行之前和之后放置警报(j)。在放置之前,警报的值在循环中是预期的,从0到6,并且由于无限循环的get请求而再次启动。但是当放置后,唯一警告的是0
for (var j = 0; j < all_posts.length; j++){
if (all_posts[j][3]){
$(".container").append(all_posts[j][0]);
}
}
以下是服务器日志:
[05/Nov/2015 06:44:02]"GET /static/jquery.js?_=1446705842818 HTTP/1.1" 200 284394
[05/Nov/2015 06:44:02]"GET /static/ui/dist/js/vendor/video.js?_=1446705842819 HTTP/1.1" 200 66306
[05/Nov/2015 06:44:03]"GET /static/ui/dist/js/flat-ui-pro.js?_=1446705842820 HTTP/1.1" 200 1031693
[05/Nov/2015 06:44:03]"GET /static/jq-cookie/jquery.cookie.js?_=1446705842821 HTTP/1.1" 200 3121
[05/Nov/2015 06:44:03]"GET /static/top_js/myads.js?_=1446705842822 HTTP/1.1" 200 9521
[05/Nov/2015 06:44:03]"GET /static/jquery.js?_=1446705842964 HTTP/1.1" 200 284394
[05/Nov/2015 06:44:03]"GET /static/ui/dist/js/vendor/video.js?_=1446705842965 HTTP/1.1" 200 66306
[05/Nov/2015 06:44:03]"GET /static/ui/dist/js/flat-ui-pro.js?_=1446705842966 HTTP/1.1" 200 1031693
[05/Nov/2015 06:44:03]"GET /static/jq-cookie/jquery.cookie.js?_=1446705842967 HTTP/1.1" 200 3121
[05/Nov/2015 06:44:03]"GET /static/top_js/myads.js?_=1446705842968 HTTP/1.1" 200 9521
[05/Nov/2015 06:44:03]"GET /static/jquery.js?_=1446705843169 HTTP/1.1" 200 284394
不断请求静态脚本。 我使用Django及其开发服务器。 附加到的html片段是:
<div class="row post">
<div class="col-md-8 col-md-offset-2 col-xs-10 col-xs-offset-1">
<div class="my-post-item">
<div class="my-post-item-inner">
<div class="my-post-item-inner-inner">
<div class="my-post-title">
<a href="#"><h4>{{post.title_line}}</h4></a>
</div>
<div class="my-post-description">
<p>{{post.description}}</p>
</div>
<div class="my-post-tags">
Tags:
{% for tag in post.tags.all %}
<span class="label label-warning">{{tag.text}}</span>
{% endfor %}
</div>
<div class="my-post-control button-group">
<button class="btn btn-success btn-secondary btn-xs btn-embossed">Edit</button>
<button class="btn btn-default btn-secondary btn-xs btn-embossed comments-button">Comments</button>
{% if post.shown %}
<button class="btn btn-warning btn-secondary btn-xs post-hide-button btn-embossed">Hide from Public</button>
{% else %}
<button class="btn btn-primary btn-secondary btn-xs post-show-button btn-embossed">Show for Public</button>
{% endif %}
<button class="btn btn-danger btn-secondary btn-xs post-delete-button btn-embossed">Delete</button>
</div>
<div class="my-post-info row">
<div class="col-xs-4 first-info-child">
<p class="first-post-time"></p>
</div>
<div class="col-xs-4">
<p class="last-modified-time"></p>
</div>
<div class="col-xs-4">
<p>Posted by: <br>{{post.poster.user_profile.first_name}} {{post.poster.user_profile.last_name}}</p>
</div>
</div>
<div class="hidden-id-info">
{{post.id}}
</div>
<div class="hidden-bg-img-info">
{{post.images.all.0.file.name}}
</div>
<div class="hidden-sorting-info" style="display: none">
<p class="last-modified-stamp">{{post.last_updated|date:"U"}}</p>
<p class="post-date-stamp">{{post.post_time|date:"U"}}</p>
<div class="hidden-popover-content" style="display: none">yap</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
好吧,我发现了问题。以防万一可能遇到同样问题而不知道究竟是什么原因的人。我错过了html文件中的结束div标签。这使得脚本标记位于带有类post的div标记内。每次运行追加时,脚本标记都会插入到文档中。浏览器将尝试不停止地访问此脚本。
我理解为什么会出现无限循环,但我不知道为什么jquery会认为它是一个缓存副本,而其他脚本也会被重新加载。