new
manish
Category
Sept. 19, 2020, 2:49 a.m.
newnwnewnenwnenwenwewewewewe
Post with Markdown Styling?
manish
Category
Sept. 15, 2020, 6:46 p.m.
This are the points which you should follow while writting a good blog:- Have a proper Introduction. Be explainatory. Use easy english language. Be consise and clear. Have a go…
------
------
------
< /code>
Я пытаюсь добавить текст на теги, содержащие идентификатор viewcount < /code>, добавив условие в мой код JavaScript, который всякий раз, когда заголовок < /code> выпускался с сервера Mathes. $(document).ready(function(){
setInterval(function()
{
$.ajax({
type:'GET',
url: "{% url 'getBlogs' %}",
success: function(response){
$("#ViewCount").empty();
for (var key in response.blogs)
{
var fromServerTitle = response.blogs[key].title;
var fromPageTitle = document.getElementById("post_title").innerText;
if (fromServerTitle == fromPageTitle) {
var temp = response.blogs[key].view_count
$("#ViewCount").append(temp);
}
//console.log(key);
}
},
error:function(response){
alert("No Data Found");
}
});
},1000);
});
Но с помощью этого кода он проверяет только для первого заголовка и вносит необходимые изменения, но я хочу, чтобы это работало для всех таких идентификаторов .
Вот экран /> < /p>
Коды шаблонов (html):-< /p>
{% for post in posts %}
{{ post.title }}
{{ post.author }}
Category
{{ post.date_posted }}
{{ post.content|truncatechars:200|safe }}
❤
{% endfor %}
$(document).ready(function(){
setInterval(function()
{
$.ajax({
type:'GET',
url: "{% url 'getBlogs' %}",
success: function(response){
$("#ViewCount").empty();
for (var key in response.blogs)
{
var fromServerTitle = response.blogs[key].title;
var initialstr = "post_"
var finalstr = initialstr.concat(response.blogs[key].pk)
var fromPageTitle = document.getElementById(finalstr).innerText;
if (fromServerTitle == fromPageTitle) {
var temp = response.blogs[key].view_count
$("#ViewCount").append(temp);
}
//console.log(key);
}
},
error:function(response){
alert("No Data Found");
}
});
},1000);
});
< /code>
Вывод консоли:-< /p>
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
(index):186 Uncaught TypeError: Cannot read property 'innerText' of null
at Object.success ((index):186)
at fire (jquery-3.5.1.js:3496)
at Object.fireWith [as resolveWith] (jquery-3.5.1.js:3626)
at done (jquery-3.5.1.js:9786)
at XMLHttpRequest. (jquery-3.5.1.js:10047)
success @ (index):186
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
done @ jquery-3.5.1.js:9786
(anonymous) @ jquery-3.5.1.js:10047
load (async)
send @ jquery-3.5.1.js:10066
ajax @ jquery-3.5.1.js:9682
(anonymous) @ (index):176
setInterval (async)
(anonymous) @ (index):174
mightThrow @ jquery-3.5.1.js:3762
process @ jquery-3.5.1.js:3830
setTimeout (async)
(anonymous) @ jquery-3.5.1.js:3868
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
fire @ jquery-3.5.1.js:3634
fire @ jquery-3.5.1.js:3496
fireWith @ jquery-3.5.1.js:3626
ready @ jquery-3.5.1.js:4106
completed @ jquery-3.5.1.js:4116
Подробнее здесь: https://stackoverflow.com/questions/639 ... javascript
Мобильная версия