Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.6k views
in Q2A Core by
edited by

I was once reporting on this issue here: Best Answer selected two times / select → unselect → select

Again and again I see this "double event" occuring, so I consider, this must a bug.

As I am writing in this post, it might be an Ajax related bug... especially because 6 events from one user happen in 1 second°!

Especially, as I disabled best answer voting using Jquery. So after chosing best answer, the button gets disabled and hidden. Even when the user visits his question again, he cannot click on best answer anymore (hidden by JS).

--

Note: Couple of months ago I realized that users can still select another answer as best, which unselected the previous selected answer. I removed this as well but still the same double event.

--

Here is an example of events in the same second that you might find in your eventlog table as well:

userX in_a_select parentid=18551    parent=array(66)    postid=18553    answe...
NULL a_select parentid=18551    parent=array(66)    postid=18553    answe...
userX in_a_unselect parentid=18551    parent=array(66)    postid=18553    answe...
NULL a_unselect parentid=18551    parent=array(66)    postid=18553    answe...
userX in_a_select parentid=18551    parent=array(65)    postid=18553    answe...
NULL a_select parentid=18551    parent=array(65)    postid=18553    answe...

 

Anonymous NULL asked. userX gave the answer.

Any idea how to solve this bug?

--

Adding 2 screenshots from today, 2013-06-06, bug:

bug

bug

Q2A version: 1.5.4
by
Extra note: When the user clicks on "best answer" the js function qa_answer_click() gets called. The first thing I am doing there is to hide "best answer" option using $(".qa-a-selection").hide();

However, even if the button is not displayed and thus not clickable by the user anymore, the bug above happens!

How strange...
by
I found out that it could be only an Ajax issue. We should call live() in function qa_ajax_post()
http://stackoverflow.com/questions/6120943/why-is-this-jquery-ajax-click-event-firing-multiple-times
http://sholsinger.com/archive/2011/08/prevent-jquery-live-handlers-from-firing-multiple-times/

Another way could be unbind() or event.stopPropagation() found here: http://forum.jquery.com/topic/jquery-ajax-submit-twice
by
I don't think it's likely to do with this, since I don't use jQuery to bind the events.
by
What is this in_a_select event? It is not part of the Q2A core. Perhaps it is related to the cause of the problem?

You can check if it's a client-side Ajax issue by seeing how many rows there are in your web server's access_log (or equivalent) file for the selection request.
by
I checked my installation: "in_a_select" only appears in NoahY's history plugin: https://github.com/NoahY/q2a-history The event is probably set in qa-history-check.php line 55, $oevent = 'in_'.$event; where $event is 'a_select'.

I checked my server logs for the selection request (great tip btw), 4 requests within the same second:

16:40:14 "POST / HTTP/1.1" 200 1914 "/30549/exponential-und-logarithmusfunktion"
16:40:14 "GET /qa-theme/customtheme/post-selected-bg.png HTTP/1.1" 200 471 "/30549/exponential-und-logarithmusfunktion"
16:40:14 "POST /30549/exponential-und-logarithmusfunktion HTTP/1.1" 302 586 "/30549/exponential-und-logarithmusfunktion"
16:40:14 "GET /30549/exponential-und-logarithmusfunktion?show=30582 HTTP/1.1" 200 9976 "/30549/exponential-und-logarithmusfunktion"

As there are 2 POST events, I still guess that it is an Ajax problem. Maybe you can see the issue better than me?
by
The Ajax request is POST / so there's only one. The most likely problem is that something in a plugin caused the Ajax response to be invalid, leading the click to be submitted again in a non-Ajax fashion. Check your server's error_log. Also you can confirm this if the page refreshes.
by
error_log is empty. I see 2 POST request above (n° 1 and 3), why do you state "there's only one"?

I checked my javascript in qa-question.js / function qa_answer_click() with the default one. I have only added code to hide the best-answer-select-button and disable it. So this should not be the problem.

PS: The error does not happen every day, just once or twice a week. But why? ... :(
by
Only "POST /" is the Ajax request - "POST /30549/exponential-und-logarithmusfunktion" is a non-Ajax submission.
by
As I see now, the "double event bug" also happens for the upvote event sometimes!

e.g.
2013-07-20 08:41:10    in_q_vote_up    postid=874    vote=1    oldvote=1
2013-07-20 08:41:10    q_vote_up    postid=874    vote=1    oldvote=1
2013-07-20 08:41:09    in_q_vote_up    postid=874    vote=1    oldvote=0
2013-07-20 08:41:09    q_vote_up    postid=874    vote=1    oldvote=0

What is the oldvote parameter by the way?
by

Please log in or register to answer this question.

...