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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:58:49+00:00 2026-05-15T08:58:49+00:00

I have a favourite and un-favourite functionality in my application and I am using

  • 0

I have a favourite and un-favourite functionality in my application and I am using jQuery. This functionality works partially. The page gets loaded, and when I click the ‘favourite’ button(it is inside add_favourite_div element), it sends a XHR request and the post is set as favourite. Then a new div called “remove_favourite_div” replaces its place.Now when I click the remove favourite(which is part of remove_favourite_div), it sends a normal http request inside of xhr.

The structure when the page gets loaded first time

<div id="favourite">        
  <div id="add_favourite_div">
     <form method="post" id="add_favourite" action="/viewpost/add_favourite">
       <div style="margin: 0pt; padding: 0pt; display: inline;">
            <input type="hidden"  
             value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" 
             name="authenticity_token">
       </div>
       <input type="hidden" value="3" name="Favourite[post_id]" 
        id="Favourite_place_id">
       <input type="hidden" value="2" name="Favourite[user_id]" id="Favourite_user_id">
       <input type="submit" value="Favourite" name="commit"><br>
      </form>
  </div>
</div>

DOM after clicking on the unfavourite button

<div id="favourite">
  <div id="remove_favourite_div">
    <form method="post" id="remove_favourite" action="/viewpost/remove_favourite">
       <div style="margin: 0pt; padding: 0pt; display: inline;">
          <input type="hidden" value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" 
          name="authenticity_token">
       </div>   
       <input type="hidden" value="3" name="Favourite[post_id]" id="Favourite_place_id">
       <input type="hidden" value="2" name="Favourite[user_id]" id="Favourite_user_id">
       <input type="submit" value="UnFavourite" name="commit"><br>  
    </form>
  </div>
</div>

In my application.js, I have two functions to trigger the xhr request

$("#add_favourite").submit(function(){
        alert("add favourite");
        action = $(this).attr("action")
        $.post(action,$(this).serialize(),null,"script");
        return false;
    });

$("#remove_favourite").submit(function(){
        alert("remove favourite");
        action = $(this).attr("action");
        $.post(action,$(this).serialize(),null,"script");
        return false;
    });

Here, when the post is initially not a favourite, favourite button is displayed and when i clicked on the button, $(“#add_favourite”).submit gets called and unfavourite form is displayed correctly, but now when I click on the un-favourite button, $(“#remove_favourite”).submit does not get called.

The whole scenario is true in both ways, I mean favourite->Unfavourite and Unfavourite->favourite

Can someone please help me to solve this
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-05-15T08:58:49+00:00Added an answer on May 15, 2026 at 8:58 am

    It was because of the DOM reloading,
    I came to know about it in a number of resources. I am posting a few

    • http://forum.jquery.com/topic/reload-dom-after-injecting-form-elements
    • http://docs.jquery.com/Events/live
    • http://docs.jquery.com/FAQ#Why_do_my_events_stop_working_after_an_AJAX_request.3F
    • http://www.learningjquery.com/2008/05/working-with-events-part-2
    • jquery doesn't see new elements
    • Rebinding events in jQuery after Ajax update (updatepanel)

    Hope it helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented Add to Favourites functionality for my iPhone application. It works fine
I have this JQuery Code, Its in the DOM Ready, on click of .deleteCatFavs
In my init I have: $contextSwitch = $this->_helper->getHelper('ForceContext'); $contextSwitch->addActionContext('favourite-listing', 'json')->initContext(); In my controller method
I am trying to implemen Add to Favorites functionality using NSMutableDictionary as I have
I have an NSMutableArray saved with NSUserDefaults. This array is my favourite items that
i'm bit stumped to know how to achieve favourite option i.e. i have a
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
I have the following code. However I get a error. How is this supposed
This semester in university I have a class called Data Structures, and the professor
I have a C application and I want to include a Scripting Language to

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.