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 8674577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:44:36+00:00 2026-06-12T19:44:36+00:00

I have an object that Im storing in a cookie, then getting the object

  • 0

I have an object that Im storing in a cookie, then getting the object and using it for some checks, that’s good and all but the problem Im having is with the line

if(!arr.hasOwnProperty($(this).val())){

in

$(".not").click(function() {
//alert($(this).val()+JSON.stringify(arr));
    if(!arr.hasOwnProperty($(this).val())){
    $.getJSON("<?php echo BASE_URL;?>json/startup/not", {id: $(this).val()}, function(json){
    if(json.status == "OK"){
        arr[json.data.id] = json.data.id;
        arr = JSON.stringify(arr);
        $.cookie('votedId', arr);
        $('#percent'+json.data.id).html(json.data.percent);
        $('#votes'+json.data.id).html(json.data.votes);
    }
    });
    }else{
        alert("Already voted on this startup!");
    }
    //alert($(this).val());
});

What happens is that for the first time I do it, it realized that it has no property by the value being passed in, and lets the vote happen. Then it doesn’t let it vote, as it should.

The problem however, is on other elements on the page that they can vote then say that there is a property by the passed in id, even though it’s not there, after the first element is voted on. It lets me vote if I refresh the page though.

Just because I feel the above is a little hard to grasp from that explanation, let me give an example.

I have multiple things with a vote hot or vote not. The first one’s id is 1, the second’s is 2, and so on. I vote that 1 is hot, so the cookie and arr array get updated to have a property 1, so it can’t be voted on again. However, after that, all other things say they’ve been voted on too, even though they haven’t been. So now I can’t vote on 2. But if I refresh the page it’s fine. But then Id have to refresh the page if I wanted to vote on element 3.

Any ideas?

  • 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-06-12T19:44:37+00:00Added an answer on June 12, 2026 at 7:44 pm

    In your code, you have:

    ...
    arr[json.data.id] = json.data.id;
    arr = JSON.stringify(arr); // <-- this is likely the reason for the error
    ...
    

    The second line above overwrites your arr variable into a string. Second time, it is string object on which you are calling .hasOwnProperty(...) – This will result in a JS error.

    This should solve it:

    ...
    arr[json.data.id] = json.data.id;
    // arr = JSON.stringify(arr); // drop this line
    $.cookie('votedId', JSON.stringify(arr)); // assign directly without overwriting arr
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml string below that I've turned into an object using $content
I have a mutable array that is retained and storing several objects. At some
I have an object that is mapped to a cookie as a serialized base-64
From all the reading that I have done, I have understood that using user-agent
I have a function that checks if a cookie (by name) exists or not:
I have an object that has a child collection: class Person { public string
I have managed objects that have image properties. Since storing large blobs in CoreData
I have a C# string object that contains the code of a generic method,
I have a Java Properties object that I load from an in-memory String ,
I have persistent object, with a string property that often is over 500 charachters.

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.