简体   繁体   中英

AJAX POST not loading class on button click.

If rating = +0 the following will show (standby).

在此处输入图片说明

If I click on the button, then the following will show( adding rating ).

在此处输入图片说明

If I click again, then the following will show ( removing rating )

在此处输入图片说明


I'd like for it to show as follows:

if rating = +0, when I click it the following will show.

在此处输入图片说明

Issue: When I click the button the font-weight:bold & color: # goes away when It should automatically update with the class. What am I doing wrong? Sorry for this lame question, just been at it for a while and I'm stuck with such a simple problem I'm sure.

This is my code:

PHP :

<div class="up vote" name="voteUp" id="<?php echo $post_iD;?>">
    <div class="wrapper">+<?php echo $VoteRate;?></div>
</div>

AJAX:

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

        if (name=='voteUp')
        {
            $.ajax(
            {
                type: "POST",
                url: "voting/up_vote.php",
                data: dataString,
                cache: false,
                success: function(html)
                {
                    parent.html(html);
                }
            });
        }
        return false;
    });
});

在成功函数中,替换.wrapper div的HTML,而不是父.wrapper的HTML:

parent.find(".wrapper").html(html);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM