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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:20:55+00:00 2026-05-16T01:20:55+00:00

I am building a web application that will let users follow discussion threads, in

  • 0

I am building a web application that will let users follow discussion threads, in Q&A format. To that end, when displaying questions, I have a “Follow” button next to each question. I want users to be able to follow these threads without reloading the page, thus using AJAX. So, I want the AJAX call to:

1) Submit a form updating the database recording following relationships; and
2) Replace “Follow” submit button with a “Following”

Here’s my JavaScript code:

$("#submitFollow").click(function() {
    var type = $("input#type").val();
    var u_id = $("input#u_id").val();
    var e_id = $("input#e_id").val();
    var dataString = 'type='+ type + '&u_id=' + u_id + '&e_id=' + e_id;

    $.ajax({
        type: "POST",
        url: "<?=site_url()?>/follow/ajaxFollow",
        data: dataString,
        success: function() {
            $('#following').html("Following");
            .hide()
            .fadeIn(1500)
        }
    });
    return false;
});
});

Here is what my form code looks like. I stripped out the action and method to keep the form from submitting itself regularly. I tried to preventDefault using JS, but that didn’t work. (The values are filled in by the model):

<div id="following">
<form id="followForm" action="" method="">
<input type="hidden" name="type" id="type" value="question">
<input type="hidden" name="u_id" id="u_id" value="1">
<input type="hidden" value="12" name="e_id" id="e_id">
<input type="submit" id="submitFollow" value="Follow Question" class="submitFollow">
</form>
</div>

Right now the controller is pretty straightforward — it just takes the array of post variables and submits them straight to the database.

I’m not too great at JavaScript, so my apologies if I’m taking up your time with a straightforward problem.

  • 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-16T01:20:56+00:00Added an answer on May 16, 2026 at 1:20 am

    I’ll just be general here, but hopefully it will help. If it were me, I would do something like the following:

    Here’s some html, generated from codeigniter:

    <div>
    questions 1
    </div>
    <div>
    <a class="follow" href="http://example.com/follow/question/1">Follow Question 1</a>
    </div>
    
    <div>
    questions 2
    </div>
    <div>
    <a class="follow" href="http://example.com/follow/question/2">Follow Question 2</a>
    </div>
    

    Then make everything work without javascript (you add that later). So here’s the codeigniter controller with some general code:

     <?php
    
    class Follow extends Controller {
    
        function Follow()
        {
            parent::Controller();
            $this->auth->restrict_to_admin();
        }
    
        function question($id = NULL)
        {
            if($id)
            {
                //get question from database using the id
                //i assume somehow the user is logged in? use their id where applicable
                echo '<span>You are now following this question</span>';
            }
        }
    
    }
    
    /* End of file follow.php */
    

    Now, whether they’re using javascript or not, it will work. Here’s where you add the javascript (I’m assuming you’re using jquery?). If not, it will be close enough.

    $(document).ready(function(){
        $('follow').click(function(event){
            event.preventDefault();
    
            var followUrl = $(this).attr('href');
            //do ajax call here.
            $.post(
            followUrl,
            {
                //any paramaters you need to add can
                //go here in this format:
                //param_key: param_value
            },
            function(responseText){
                //here you can update the clicked link to say something
                //like "you are now following this question"
                //the responseText var will have whatever text the server responds with.
                //just responsd with html
            },
            'html'
            );
    
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.