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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:14:49+00:00 2026-06-19T04:14:49+00:00

The ajax request functions where: success: function(data) { $(‘#totalvotes1’).text(data); } and where <span id=totalvotes1>

  • 0

The ajax request functions where:

success: function(data) {
   $('#totalvotes1').text(data); 
}

and where <span id="totalvotes1">,

but I need it to work with unique id’s where:

success: function(data) { 
    $('#total_' + $(this).attr("id")). text(data); 
}

and where <span id="total_vote_up_<?php echo $mes_id; ?>">

and <a id="vote_up_<?php echo $mes_id1; ?>">

I cannot figure out what is wrong with the following code. If anybody has an easy fix with json I would try that but I have no idea how json works. I would love it if somebody could just help me debug this code here

general.js:

$(".vote").click(function() 
{
    var id = $(this).attr("id");
    var name = $(this).attr("name");
    var eData = $(this).attr("data-options");
    var dataString = 'id='+ id + '&' + eData ;
    var parent = $(this);

    if(name=='up')
    {
        $(this).fadeIn(200).html('');
        $.ajax({
            type: "POST",
            url: "up.php",
            data: dataString,
            cache: false,

            success: function(data) { 
                $('#total_' + $(this).attr("id")).text(data); 
            }
        });
    }

});
});
});

index.php

<div id="main">
<div id="left">
    vote_up_<?php echo $mes_id1; ?>
<span class='up'><a id="vote_up_<?php echo $mes_id1; ?>" class="vote" name="up" data-options="key1=<?php echo $mes_id1;?>&key2=<?php echo $mes_id2;?>&key3=<?php echo $totalvotes1;?>&key4=<?php echo $totalvotes2;?>"> <img src="up.png" alt="Down" /></a></span><br />
<span id="total_vote_up_<?php echo $mes_id1; ?>"><?php echo $totalvotes1; ?></span><br />
</div>
<div id="message">
    <?php echo $message1; ?>
</div>
<div class="clearfix"></div>
 </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-19T04:14:50+00:00Added an answer on June 19, 2026 at 4:14 am

    Identation and enters are your friends.

    Try doing something like this:

    // Before $.ajax
    var that = this;
    // Inside success
    $('#total_' + $(that).attr("id")).text(data);
    

    Most jQuery functions change the context, so “this” inside the success function does not point to the “.vote” element. You have to save the reference to the element (usually with something like “var that = this”) and use this reference inside the success function.

    Edit:

    As Matt Burland pointed out, you already have both the clicked element reference saved (parent) and the id saved, so this can be solved with something like:

    $('#total_' + id).text(data); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Ajax request: $.ajax({ url: MyPage.aspx, data: params, success: function(data) { //
I use this pseudo-class to make Ajax request to server: function RequestManager(url, params, success,
I have a very simple ajax request: $.get(url, data) .done(function () { }) .fail(function
I create a function in CakePHP controller class to process AJAX request. But I
Ext.Ajax.request({ url: 'foo.php', // where you wanna post success: passFn, // function called on
EDIT JQUERY-AJAX REQUEST CODE: <script type=text/javascript> $(document).ready(function(){ $(.form).submit( function(e) { e.preventDefault(); var form =
this works: $.ajax({ type: 'POST', url: 'register.php', data: {captcha: captcha }, success: function() {
I have a jquery function for sending email with ajax request; function sendMail(from,to,subject,message){ var
I have a php function which returns JSON in response to a ajax request
I am getting this error on a js function that sends an ajax request

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.