Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6648069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:36:43+00:00 2026-05-26T00:36:43+00:00

I have a bit of a dillema :) I have a link for users

  • 0

I have a bit of a dillema 🙂

I have a link for users to vote on an item. A click on a link generated a jQuery AJAX call checking if the person is logged in. If not, the dialog box displays a form to login.

But the problem is that the jQuery call to log in and the whole bit with the popup box is in a different place.

What I need to do is check if user got logged in successfully, and update the vote count.

I am doing it on this site: http://www.problemio.com

Here is my jQuery code so far:

<script type="text/javascript">
$(document).ready(function() 
{
     var $dialog = $('#loginpopup')
       .dialog({
         autoOpen: false,
         title: 'Login Dialog'
       }); 

        $("#newprofile").click(function () {
          $("#login_div").hide();
          $("#newprofileform").show();
        });


    $('.vote_up').click(function() 
    {        
        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=+';

        $.ajax({
                type: "POST",
                url: "/problems/vote.php",
                dataType: "json",
                data: dataString,
                success: function(data)
                {           
                    // ? :)
                    alert (data);   
                },
                error : function(data) 
                {
                    errorMessage = data.responseText;

                    if ( errorMessage == "not_logged_in" )
                    {
                        // Try to create the popup that asks user to log in.
                        $dialog.dialog('open');

                        // prevent the default action, e.g., following a link
                        return false;
                    }
                    else
                    {
                        alert ("not");
                    }

                    //alert(JSON.stringify(data));
                }
            });


        //Return false to prevent page navigation
        return false;
    });

    $('.vote_down').click(function() 
    {
        alert("down");

        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=-';        

        //Return false to prevent page navigation
        return false;
    });    
});
</script>

It all works except right after the line $dialog.dialog('open'); – I don’t know how to

  1. Get a signal back for success of fail, and don’t know exactly how to
  2. Update the very item that was voted on since it is just one of many items that can be voted on in the page.

How can I do these two things?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:36:43+00:00Added an answer on May 26, 2026 at 12:36 am

    Try this approach:

    1. Have a hidden input within the div that is your login dialog.
    2. Set that with the problem_id before you do the .dialog('open')
    3. On the success callback of the Login button click, retrieve problem_id from the hidden input and perform vote-up or vote-down.

    Hope that helps

    EDIT: (Trying to code a workable example after OP’s second comment)

    <script type="text/javascript">
        $(document).ready(function() {
            var $dialog = $('#loginpopup')
                    .dialog({
                        autoOpen: false,
                        title: 'Login Dialog'
                    });
    
            var $problemId = $('#theProblemId', '#loginpopup');
    
            $("#newprofile").click(function () {
                $("#login_div").hide();
                $("#newprofileform").show();
            });
    
    
            $('.vote_up').click(function() {
                var problem_id = $(this).attr("data-problem_id");
                voteUp(problem_id);
                //Return false to prevent page navigation
                return false;
            });
    
            var voteUp = function(problem_id) {
                var dataString = 'problem_id=' + problem_id + '&vote=+';
    
                $.ajax({
                    type: "POST",
                    url: "/problems/vote.php",
                    dataType: "json",
                    data: dataString,
                    success: function(data) {
                        // ? :)
                        alert(data);
                    },
                    error : function(data) {
                        errorMessage = data.responseText;
                        if (errorMessage == "not_logged_in") {
                            //set the current problem id to the one within the dialog
                            $problemId.val(problem_id);
    
                            // Try to create the popup that asks user to log in.
                            $dialog.dialog('open');
    
                            // prevent the default action, e.g., following a link
                            return false;
                        }
                        else {
                            alert("not");
                        }
    
                        //alert(JSON.stringify(data));
                    }
                });
            };
    
            $('.vote_down').click(function() {
                alert("down");
    
                problem_id = $(this).attr("data-problem_id");
    
                var dataString = 'problem_id=' + problem_id + '&vote=-';
    
                //Return false to prevent page navigation
                return false;
            });
    
            $('#loginButton', '#loginpopup').click(function() {
                $.ajax({
                    url:'url to do the login',
                    success:function() {
                        //now call cote up 
                        voteUp($problemId.val());
                    }
                });
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this bit of html. (Link at bottom) Its output of php code
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
Have a bit of problem with the jQuery clone() functionality. Basically I have a
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:
I have a question regarding how initialization vector works on cryptography. I have bit
Have a bit of confusion here. I added a few objects from a class
I have a bit of a theoretical question, however it is a problem I
I have a bit of code that fits theoretical prediction to experimental data, and
I have a bit of a problem that I can't seem to code my
I have a bit of a strange problem. I have a music app that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.