javascript - (this).parent().find 无法在 ajax 调用中获取响应

标签 javascript jquery ajax dom

$(".content-short").click(function() {
      $(".content-full").empty();
      var contentid=$(this).parent().find(".content-full").attr('data-id');
      var content=$(this).parent().find(".content-full");
      alert(contentid);
      var collegename = $(this).attr('data-id');
      $.ajax({
          type: "post",
          url: "contenthome.php",
          data: 'collegename=' + collegename,
          dataType: "text",                  
          success: function(response) {            

            $content.html(response);
          }
      });
    });

此处警报显示特定的数据 ID,但

content=$(this).parent().find(".content-full");

这不会在内容完整的 div 中显示具有特定数据 ID 的数据 代码有什么问题或者其他什么吗?

如果我使用(."content-full");查询会显示数据;而不是

$(this).parent().find(".content-full");

最佳答案

在 ajax 回调中,您使用 $content,但将变量声明为 content。这可能是问题所在吗? 你的问题不清楚。你想达到什么目的?

关于javascript - (this).parent().find 无法在 ajax 调用中获取响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32164795/

相关文章:

javascript - 如何在javascript函数onChange中传递两个参数

javascript - 降低包含多个 javascript 的成本

javascript - 创建时将部分字符串设为粗体

javascript - 如何返回文档准备好的函数?

php - 如何将 php 变量传递给 ajax

javascript - MVC - 布局加载部分 View ,但不触发 javascript

jquery - 如何根据成功处理程序中的返回值隐藏按钮?

javascript - VueJS 在 v-model 中反转值

javascript - 如何隐藏当前页面

javascript - jQuery - 比较两个值并显示或隐藏 div