I intend to have a poll page which user can switch between poll and
result, triggered by clicking on a centain link, which is returned by
GET method.

now I am stuck because both function works on the first click, but
when user try to click on the returned link, corresponding click event
is not triggered, ie. poll -> result -> poll is broken on second step,
and gives no javascript error.

data returned is correct, so it should be something wrong with my
code.

        $('#view_poll').click(function() {poll_id = $(this).attr("name");
poll_result(poll_id); return false;});
        $('#goto_poll').click(function() {poll_id = $(this).attr("name");
poll_booth(poll_id); return false;});

        function poll_result(poll_id) {
                if(!is_being_voted) {
                        is_being_voted = true;
                        $('#polls-' + poll_id + '-loading').fadeIn("slow");
                        $('#polls-' + poll_id + 
'-ans').fadeOut("normal",function () {
                                datapassed = 'pollresult=' + poll_id;
                                $.ajax( {
                                        url : polls_ajax_url, type : "GET", 
data : datapassed, dataType :
"html", cache : false, error : function() {
                                                $('#polls-' + 
poll_id).append('<p>Unexpected Error: Please
reload this page and try again.</p>');
                                        }, success : function(d1) {
                                                $('#polls-' + poll_id + 
'-loading').fadeOut("slow");
                                                $('#polls-' + poll_id + '-
ans').empty().append(d1).fadeIn("normal");
                                                is_being_voted = false;
                                        }
                                } );
                        });
                } else {
                        alert(polls_text_wait);
                }
        };

        function poll_booth(poll_id) {
                if(!is_being_voted) {
                        is_being_voted = true;
                        $('#polls-' + poll_id + '-loading').fadeIn("slow");
                        $('#polls-' + poll_id + 
'-ans').fadeOut("normal",function () {
                                datapassed = 'pollbooth=' + poll_id;
                                $.ajax( {
                                        url : polls_ajax_url, type : "GET", 
data : datapassed, dataType :
"html", cache : false, error : function() {
                                                $('#polls-' + 
poll_id).append('<p>Unexpected Error: Please
reload this page and try again.</p>');
                                        }, success : function(d1) {
                                                $('#polls-' + poll_id + 
'-loading').fadeOut("slow");
                                                $('#polls-' + poll_id + '-
ans').empty().append(d1).fadeIn("normal");
                                                is_being_voted = false;
                                        }
                                } );
                        });
                } else {
                        alert(polls_text_wait);
                }
        };

Reply via email to