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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:08:46+00:00 2026-06-05T00:08:46+00:00

This is probably a newbie question, but i really need help. I am creating

  • 0

This is probably a newbie question, but i really need help.

I am creating a wishlist in an online store, and if the user is logged in, the wishlist item is going to be saved in the database and non logged in user’s wishlist will be saved via cookies and I am using AJAX for the wishlist functionality. Everything goes well except that the cookies are not updated in the first ajax request.

This is my first steps(ajax):

  1. call ajax request to update wishlist
  2. reload wishlist template based on the new cookie

the above steps doesnt update automatically the wishlist template $_COOKIE[] needs a page refresh.

This is my updated steps(ajax)

  1. call ajax request to update wishlist
  2. call another ajax request to reload wishlist template

the above code solves the problem, (the number 2 step is called to just refresh the $_cookie value.), but it takes two ajax requests to update the wishlist, which takes a little time to work. Im sure, this is not the best solution. I know this is a better solution for this.

Help pls 🙂

Thanks

  • 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-05T00:08:48+00:00Added an answer on June 5, 2026 at 12:08 am

    Cookies can be set by javascript alone. As you are using ajax I think you can handle cookies fine without any page refresh.

    Here is the logic you should implement.

    1. Send an Ajax request to your PHP page.
      • if you are logged in, PHP saves the data in database and return a status value 1.
      • Otherwise PHP returns a status value of 0. Means you were not logged in and couldn’t save it in Database.
      • While returning 0, PHP can populate $_COOKIE superglobal. It’ll set the cookies in browser when the request is finished.
    2. On the callback event of your ajax request you check the status value. if its 0 just save the data in cookie. This cookie is available via document.cookie. This can be easily done by jquery

    sample code using jQuery

    // ajax.js
    $.post("updatewishlist.php", 
    {
        'wishlist_item':'wishlist_value'
    },
    function(json){
    // callback function
        if(json.status==0){
            $.cookie('the_cookie', 'the_value', { expires: 7 });
        }
    });
    

    Here I have used jquery cookie plugin

    // updatewishlist.php
    <?php
    if(user_logged_in()){
    // sanitize input here
    // update database with $_POST['wishlist_item']
    $status = 1;
    }else{
    // update the cookie
    // manipulate $_COOKIE super global
    $status = 0;
    }
    
    // echoing json
    
    echo json_encode(array('status' => $status));
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a really newbie question (well, I'm pretty sure it is), but
This is probably a really stupid newbie-sounding question to you developer type people, but
I realize this is probably a hopelessly newbie question, but what is the difference
This is probably a newbie question, but is it possible to add a sprite
This is probably a newbie question, but I can't seem to think of a
I know this is probably a newbie question, but is it possible to do
This is probably a very newbie question but what I'm trying to do is
I know this probably must be a newbie question, but since I don't know
Okay, this is probably a very newbie question, but how can I get to
I need some help with what is probably a newbie question in terms of

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.