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

  • Home
  • SEARCH
  • 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 9086337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:27:52+00:00 2026-06-16T21:27:52+00:00

I have the following jQuery code which does not work as I expect it.

  • 0

I have the following jQuery code which does not work as I expect it. I am sure I am doing something wrong, but I dont see it. Basically if a blog is not publish, when I click on the image, it accesses my DB and updates it accordingly. All of that is fine.

  1. I click on .not_published
  2. The content of .not_published is changed with an image tag that display ajax-loader.gif
  3. When the server returns a success message, I update the html of #not_published parent with a new content which includes replacing .not_published with .published.

Blog Post List

All I get when I click on the .not_published is the ajax image loading and it stays there. If I add an alert("message'); inside the success function it works fine.

Loading Image

List point 3 does not work. I cant figure out why. Please see code below:

jQuery Code:

$(document).on('click','.not_published', function(){
       var ID = $(this).siblings("p").text();
        $(this).html("<img style=\"padding-left:15px;\" src=\"/img/admin/ajax-loader.gif\">");
        $.ajax({
            url: "/posts/publish/"+ID,
            type: "post",
            data: '',
            success: function(responseText, statusText, xhr, $form){
                $(this).parent().html("<span class=\"published\"><img style=\"width:20px;\" src=\"/img/admin/checkmark_green.png\"></span><p style=\"display: none\">ID</p>");
            },
            error: function(responseText){
                alert(responseText);
            }   
        });
});

HTML Code

<div id="publish">
    <span id="not_published">
        <img style="width:20px"  src="/img/admin/checkmark_red.png">
    </span>"
    <p style="display: none">1</p>
</div>
  • 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-16T21:27:54+00:00Added an answer on June 16, 2026 at 9:27 pm

    Store the element in variable outside of the AJAX request but before you do… inside success handler log this to console. It’s not what you think it is.

    ALso changing ID to class as noted in comments

    $(document).on('click','.not_published', function(){
           var ID = $(this).siblings("p").text();
            var $el=$(this).html("<img style=\"padding-left:15px;\" src=\"/img/admin/ajax-loader.gif\">");
    
            $.ajax({
                url: "/posts/publish/"+ID,
                type: "post",
                data: '',
                success: function(responseText, statusText, xhr, $form){
                     /* change $(this) to $el defined above*/
                    $el.parent().html("<span class=\"published\"><img style=\"width:20px;\" src=\"/img/admin/checkmark_green.png\"></span><p style=\"display: none\">ID</p>");
                },
                error: function(responseText){
                    alert(responseText);
                }   
            });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery code which doesn't work quite right when trying to
I have the following JavaScript code which I like to convert to jQuery but
I have the following jQuery code which I like to convert to work with
I have the following jQuery code which runs when I'm clicking an option in
I have the following jQuery code: $(body.page-calendar-practices-2012-05 #content-header h1#title) which works fine. I can
I have the following code alternatives, neither of which is satisfactory. I'm using jQuery
I have the following Code which I know doesn't work correctly. Yes I know
I have the below code that does not seem to work at all :(
Not sure where I might have went wrong the code seems fine to me,
i have the following jQuery code. $(function() { $('.clickme').click(function() { $('.totalthing').slideToggle('slow','easeInOutQuart', function() { //

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.