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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:40:36+00:00 2026-06-11T06:40:36+00:00

I have a method in my controller that lets users check something called POE

  • 0

I have a method in my controller that lets users check something called “POE Status”.
This returns a string that i display in a div tag on my view. I also provide 2 buttons. one to enable POE and the other to disable. Both the enable and disable commands will return the POE status as a result.
So I’m trying to use ajax to update the page with the new status once either one of the two buttons are clicked.

What I’m noticing is that both buttons will work the first time the page is loaded. But after the initial ajax call is made and the view updated, if i try to use the buttons again, nothing happens.

I have the following HTML: (i’m not including all the html, just the parts that I think matter….)

  <div class="span6" id="clientajaxcontainer">

      <h2>Port POE Status: Port <?php echo $portname;?></h2>
      <p><p>
      <?php echo $poeStatus;?>                
      <button class="btn" id="enable">Enable POE</button>&nbsp;
      <button class="btn" id="disable">Disable POE</button>              
  </div>

Then I have the following javascript:

  <script>
 //Enable POE button
  $('#enable').click(function()  {
   alert('in POEOn');
   console.log('On');
  //disbled button until ajax request is done. 
  $(this).attr("disabled","disabled");
  $('#disable').attr("disabled","disabled");
  var htmlstring;
  $.ajax({
    url:"<?php echo site_url('controller/poeOn);?>",
    type:'POST',
    dataType:'text',
    success: function(returnDataFromController) {
    htmlstring = "<h2>Port POE Status: Port " + $('#port').val() + "</h2><p><p>" + returnDataFromController + "<button class='btn' name='enable' id='enable'>Enable POE</button>&nbsp;<button class='btn' name='disable' id='disable'>Disable POE</button>";    
    alert(htmlstring);
    $('#clientajaxcontainer').html(htmlstring); 
    console.log(htmlstring);
  }
});
//re-enable the buttons.
$(this).removeAttr("disabled");
$('#disable').removeAttr("disabled");
  });


//Disable POE button
  $('#disable').click(function()  {
alert('in POEoff');
console.log('Off');
//disbled button until ajax request is done. 
$(this).attr("disabled","disabled");
$('#enable').attr("disabled","disabled");

$.ajax({
  url:"<?php echo site_url('controller/poeOff);?>",
  type:'POST',
  dataType:'text',
  success: function(returnDataFromController) {
    htmlstring = "<h2>Port POE Status: Port " + $('#port').val() + "</h2><p><p>" + returnDataFromController + "<button class='btn' name='enable' id='enable'>Enable POE</button>&nbsp;<button class='btn' name='disable' id='disable'>Disable POE</button>";    

    alert(htmlstring);
    $('#clientajaxcontainer').html(htmlstring); 
    console.log(htmlstring);
}
  });
  //re-enable the buttons.
  $(this).removeAttr("disabled");
  $('#enable').removeAttr("disabled");
});    

</script>

Can you tell me where I’m going wrong?
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-11T06:40:38+00:00Added an answer on June 11, 2026 at 6:40 am

    The problem is that you are not creating a “live” binding for your buttons and once you call $('#clientajaxcontainer').html(htmlstring); you replace the buttons with new elements which do not have a click binding. Try this instead:

    $('#enable').live('click', function()  {
        //...
    }
    
    $('#disable').live('click', function()  {
        //...
    }
    

    If you’re using jQuery 1.8 you can use the on() method instead of live(). That would look like this:

    $(document).on('click', '#enable', function()  {
        //...
    }
    
    $(document).on('click', '#disable', function()  {
        //...
    }
    

    Here’s the relevant documentation:

    • http://api.jquery.com/live/
    • http://api.jquery.com/on/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller method that is a little something like this: def suggestions
I have a controller method that returns a jSON object and in one calling
i have a quetion about MVC routing. I have a controller method that is
In Ruby on Rails, I have an update method in a controller, that is
I have an annotated controller with a method that expects a model and a
I have a Rails controller action to test. In that action, a method User.can?
I have a controller method called Edit in which the user can edit data
Currently, I have a Controller with an Index() action method that needs authorization: public
I have this code that lets me create a custom UIBarButton which is inside
I have a few methods inside my view controller that load up for future

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.