Re: Django +Ajax + jQuery problem

2020-07-03 Thread Andréas Kühne
Hi,

The reason for this is that you are replacing the buttons when you update
the answer. The event listener that you attached is on the first one and
not the second one.
You can solve this in 2 ways:

1. Reregister the event listener when you have loaded the answer again.
2. Use a different way to add the event listeners in the first place. You
can register it this way instead: $('body').on('click', '.upvote',
function() {});

Regards,

Andréas


Den tors 2 juli 2020 kl 19:16 skrev Jan Gregorczyk :

> My problem is that site registers only the first click on .upvote or
> .downvote element and ignores next ones.
> {% extends 'base.html' %}
> {% load votes_exists %}
> {% block title %}{{question.title|truncatechars:52}}{% endblock %}
> {% block content %}
> {{question.title}}
> {{question.content}}
> {% for answer in question.answers.all %}
> {{answer.author}}
> {{answer.content}}
>
> 
> {% votes_up_exists answer request.user.id as is_upvoted %}
> {% votes_down_exists answer request.user.id as is_downvoted %}
> ↑
> {{answer.vote_score}}
> ↓
> 
> {% endfor %}
> 
> {% csrf_token %}
> {{form.as_p}}
> 
> 
> {% endblock %}
> {% block javascript %}
> {% load static %}
> https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js";>
> 
> //upvote and downvote script
> var csrftoken = window.Cookies.get('csrftoken');
> function csrfSafeMethod(method) {
> // these HTTP methods do not require CSRF protection
> return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
> }
> $.ajaxSetup({
> beforeSend: function(xhr, settings) {
> if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
> xhr.setRequestHeader("X-CSRFToken", csrftoken);
> }
> }
> });
> $(".upvote").click( function() {
> let answerid = $(this).data("answer-id");
> $.post("{% url 'upvote' %}", {answer_id:answerid}, function(response) {
> /*$("#score-" + answerid).load(window.location.href + " " + "#score-" +
> answerid);
> $("#upvote-" + answerid).load(window.location.href + " " + "#upvote-" +
> answerid);
> $("#downvote-" + answerid).load(window.location.href + " " + "#downvote-"
> + answerid);*/
> $("#answer-" + answerid).load(window.location.href + " " + "#answer-" +
> answerid);
> alert(response);
> });
> });
> $(".downvote").click( function() {
> let answerid = $(this).data("answer-id");
> $.post("{% url 'downvote' %}", {answer_id:answerid}, function(response) {
> /*
> $("#score-" + answerid).load(window.location.href + " " + "#score-" +
> answerid);
> $("#upvote-" + answerid).load(window.location.href + " " + "#upvote-" +
> answerid);
> $("#downvote-" + answerid).load(window.location.href + " " + "#downvote-"
> + answerid);*/
> $("#answer-" + answerid).load(window.location.href + " " + "#answer-" +
> answerid);
> alert(response);
> });
> });
> 
> {% endblock %}
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFyHfE3_EogRCb-2xvGpS6ACDNPbF_JxBLzsfD%3D2XLoBKsJysA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCeOLmLxGDSQuEzCN51Pr6%2BRWfwNc8UqvrAAsj_JMQFWEw%40mail.gmail.com.


Django +Ajax + jQuery problem

2020-07-02 Thread Jan Gregorczyk
My problem is that site registers only the first click on .upvote or
.downvote element and ignores next ones.
{% extends 'base.html' %}
{% load votes_exists %}
{% block title %}{{question.title|truncatechars:52}}{% endblock %}
{% block content %}
{{question.title}}
{{question.content}}
{% for answer in question.answers.all %}
{{answer.author}}
{{answer.content}}


{% votes_up_exists answer request.user.id as is_upvoted %}
{% votes_down_exists answer request.user.id as is_downvoted %}
↑
{{answer.vote_score}}
↓

{% endfor %}

{% csrf_token %}
{{form.as_p}}


{% endblock %}
{% block javascript %}
{% load static %}
https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js
">

//upvote and downvote script
var csrftoken = window.Cookies.get('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$(".upvote").click( function() {
let answerid = $(this).data("answer-id");
$.post("{% url 'upvote' %}", {answer_id:answerid}, function(response) {
/*$("#score-" + answerid).load(window.location.href + " " + "#score-" +
answerid);
$("#upvote-" + answerid).load(window.location.href + " " + "#upvote-" +
answerid);
$("#downvote-" + answerid).load(window.location.href + " " + "#downvote-" +
answerid);*/
$("#answer-" + answerid).load(window.location.href + " " + "#answer-" +
answerid);
alert(response);
});
});
$(".downvote").click( function() {
let answerid = $(this).data("answer-id");
$.post("{% url 'downvote' %}", {answer_id:answerid}, function(response) {
/*
$("#score-" + answerid).load(window.location.href + " " + "#score-" +
answerid);
$("#upvote-" + answerid).load(window.location.href + " " + "#upvote-" +
answerid);
$("#downvote-" + answerid).load(window.location.href + " " + "#downvote-" +
answerid);*/
$("#answer-" + answerid).load(window.location.href + " " + "#answer-" +
answerid);
alert(response);
});
});

{% endblock %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFyHfE3_EogRCb-2xvGpS6ACDNPbF_JxBLzsfD%3D2XLoBKsJysA%40mail.gmail.com.


Re: django ajax jquery

2013-08-15 Thread carlos
Hi
maybe you need find in google.com for example


http://fromzerotocodehero.blogspot.com/2011/01/django-ajax-tutorial-part-1.html

I think there are more tutorials

Cheers,


On Thu, Aug 15, 2013 at 6:09 AM, Scheck Nyori  wrote:

> Hello!
> I am a noob in web development. Just finished polls tuts. Can anyone give
> me any insight in using jquery and ajax with django! If possible any
> tutorial. Any help will be appreciated!
> Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


django ajax jquery

2013-08-15 Thread Scheck Nyori
Hello!
I am a noob in web development. Just finished polls tuts. Can anyone give
me any insight in using jquery and ajax with django! If possible any
tutorial. Any help will be appreciated!
Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Django+Ajax+jquery

2012-08-03 Thread Rishabh Dixit
Someone please give some solution to this stack overflow question-

http://stackoverflow.com/questions/11706721/updating-a-button-value-database-and-call-a-view-function-without-refreshing-th

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/TsUurybMHq8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django + Ajax + Jquery

2010-06-06 Thread Massimiliano della Rovere
This is useful too: http://www.dajaxproject.com/

On Mon, Jun 7, 2010 at 07:57, Dmitry Dulepov  wrote:
> Hi!
>
> tazimk wrote:
>>     I want to use ajax in my templates using jquery.
>>     Can someone provide me some sample examples /links related to
>> this.
>
> http://www.google.com/ may be? The question is too broad.
>
> --
> Dmitry Dulepov
> Twitter: http://twitter.com/dmitryd/
> Web: http://dmitry-dulepov.com/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django + Ajax + Jquery

2010-06-06 Thread Dmitry Dulepov
Hi!

tazimk wrote:
> I want to use ajax in my templates using jquery.
> Can someone provide me some sample examples /links related to
> this.

http://www.google.com/ may be? The question is too broad.

-- 
Dmitry Dulepov
Twitter: http://twitter.com/dmitryd/
Web: http://dmitry-dulepov.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django + Ajax + Jquery

2010-06-06 Thread Andy Kelley
I'll go ahead and insert a plug here:

http://github.com/superjoe30/jst-parser

On Jun 6, 12:14 am, tazimk  wrote:
> Hi,
>
>     I want to use ajax in my templates using jquery.
>     Can someone provide me some sample examples /links related to
> this.
>     Also some sample examples on using Jquery efficiently

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django + Ajax + Jquery

2010-06-06 Thread Horst Gutmann
Django itself doesn't really care what JS framework you use and only
offers some framework agnostic helpers within the request object like
http://docs.djangoproject.com/en/1.2/ref/request-response/#django.http.HttpRequest.is_ajax
to distinguish requests coming as XHRs as well as
django.utils.simplejson for providing Python-version independent JSON
(de)serialization.

If you want more, there are some apps out there like dajax [1] out there :-)

[1] http://www.dajaxproject.com/

On Sun, Jun 6, 2010 at 9:14 AM, tazimk  wrote:
> Hi,
>
>    I want to use ajax in my templates using jquery.
>    Can someone provide me some sample examples /links related to
> this.
>    Also some sample examples on using Jquery efficiently
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django + Ajax + Jquery

2010-06-06 Thread tazimk
Hi,

I want to use ajax in my templates using jquery.
Can someone provide me some sample examples /links related to
this.
Also some sample examples on using Jquery efficiently

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django + Ajax + Jquery

2010-06-06 Thread tazimk
Hi,

I want to use ajax in my templates using jquery.
Can someone provide me some sample examples /links related to
this.
Also some sample examples on using Jquery efficiently

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.