Javascript 未捕获类型错误:无法读取属性';html';未定义的属性-AJAX仅在spesific div中发布答案

Javascript 未捕获类型错误:无法读取属性';html';未定义的属性-AJAX仅在spesific div中发布答案,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我有一个错误: 未捕获的TypeError:无法读取未定义的属性“html” 我试图创建的是一个投票系统,用于数据库中我页面上的每个视频。我已经成功地使用AJAX实现了这一点。唯一的问题是,我无法在正确的div类“this”中输出答案,因为它与类一起发布在每个div中,所以在每个视频下都会发布 我需要一个有效的解决方案来识别用户单击投票按钮的父div,并只更改其自己的子div 请帮忙。这是我的jQuery代码 $(function() { $(".vote").click(functi

我有一个错误:

未捕获的TypeError:无法读取未定义的属性“html”

我试图创建的是一个投票系统,用于数据库中我页面上的每个视频。我已经成功地使用AJAX实现了这一点。唯一的问题是,我无法在正确的div类“this”中输出答案,因为它与类一起发布在每个div中,所以在每个视频下都会发布

我需要一个有效的解决方案来识别用户单击投票按钮的父div,并只更改其自己的子div

请帮忙。这是我的jQuery代码

$(function() {

    $(".vote").click(function() {  

        var id = $(this).attr("id");
        var name = $(this).attr("name");
        var dataString = 'id='+ id ;
        var acdc = $('#ab').attr('class');
        var potato = 'potato';
        var parent = $(this);
        if(name=='up')
        { 
            $.ajax({
                type: "POST",
                url: "up_vote.php",
                data: dataString,
                cache: false,
                success: function(html) { acdc.html(html);
                                        }}); 
        }
        else
        {
            $(this).fadeIn(200).html('<img src="img/icon-down.png" align="absmiddle"     style="height: 10px;width:10px;">');
            $.ajax({
                type: "POST",
                url: "down_vote.php",
                data: dataString,
                cache: false,
                success: function(html){ 
                    parent.parent().find('.this').html(html);
                }}); 
        }
        return false;
    });

});
$(函数(){
$(“.vote”)。单击(函数(){
var id=$(this.attr(“id”);
var name=$(this.attr(“name”);
var dataString='id='+id;
var acdc=$('#ab').attr('class');
马铃薯变种=‘马铃薯’;
var parent=$(这是);
如果(名称=='up')
{ 
$.ajax({
类型:“POST”,
url:“up_vote.php”,
数据:dataString,
cache:false,
成功:函数(html){acdc.html(html);
}}); 
}
其他的
{
$(this.fadeIn(200.html)(“”);
$.ajax({
类型:“POST”,
url:“down_vote.php”,
数据:dataString,
cache:false,
成功:函数(html){
parent.parent().find('.this').html(html);
}}); 
}
返回false;
});
});
这是带有视频帖子和div类“this”的html,我的AJAX答案应该在这里发布——但只在当前版本中发布——因为php脚本只为带有spesific id的视频添加了一票,而不是全部

 <div class='botto'>
  <div class='icon-wrap'>
   <form action="blossom.php" method="post"><?php $id =  $row["idv"]; ?>
   <input type="hidden" id="id" value="<?php echo $row['idv']; ?>" />
   <div cass='homesick'>
    <button type='submit'name='up' style="background-color:transparent; border-color:transparent;outline: none; " class='icon vote' name="up"><img src='img/thumbsup.png' alt='up' name='up' class='icon vote icon-up' id="<?php echo $row['idv']; ?>" ></button> 
         <span class='number-vote this'>
         <?php

         echo $row['votev'];

         ?></span>
    <button type='submit' name='down' style="background-color:transparent; border-color:transparent;outline: none; " class="vote" name="down"><img src='img/icon-down.png' alt='down' class='icon icon-down vote' id="<?php echo $row['idv']; ?>"></button> 
    </div>
   </form>
  </div>
  </div>

var acdc=$('#ab').attr('class')
尝试检索属性
class
的字符串值,在本例中,该属性解析为
未定义的

如果要使用jQuery方法,应该在DOM节点上执行,例如:

var acdcElement = $('#ab');
var html = acdcElement.html();
var acdc=$('#ab').attr('class')
尝试检索属性
class
的字符串值,在本例中,该属性解析为
未定义的

如果要使用jQuery方法,应该在DOM节点上执行,例如:

var acdcElement = $('#ab');
var html = acdcElement.html();

这个问题和你之前的问题有什么区别?你的HTML中没有
id='ab'
,什么是
$(“#ab”).attr('class')
应该返回?video.php:576 Uncaught TypeError:acdc.HTML不是一个函数,上面写着什么-我添加了>>>和>>var acdc=$('number vote')。attr('id');没有区别。我在这个问题上陷入了困境。正在寻求帮助。仅此而已。这与您之前的问题有什么区别?您的HTML中没有
id='ab'
,应该返回的
$(“#ab”).attr('class')
是什么?video.php:576 Uncaught TypeError:acdc.HTML不是这里所说的函数-我添加了>>>和>>var acdc=$('.number vote').attr')。attr('id');没有区别。我在这个问题上陷入了困境。正在寻求帮助。这都是相同的错误-$(“.vote”)。点击(function(){var id=$(this).attr(“id”);var name=$(this.attr(“name”);var dataString='id='+id;var acdc=$('.#ab')。attr('class');var acdcElement=$('.#ab');var html=acdcElement.html();var potato='potato';var parent=$(this);if(name='up'){.ajax('type:'POST',url:“up_vote.php”,数据:dataString,cache:false,success:function(html){acdc.html(html)}}}elsesame error-here-$(“.vote”)。单击(function(){var id=$(this.attr(“id”);var name=$(this.attr(“name”);var dataString='id='+id;var-acdc=$('ab').attr('class');var-acdcElement=$('ab'));var html=acdcElement.html();var potato='potato';var parent=$(此);if(name='up'){$.ajax({type:“POST”,url:“up_vote.php”,数据:dataString,cache:false,success:function(html){acdc.html(html);}}}else