javascript - 在 Ajax 循环中添加文本功能已损坏

标签 javascript ajax

我想使用 done_by 类更改每个范围的文本,因此我使用了 Ajax。

由于某些原因,我必须将每个范围的 ID 发送到我的 display_name.php。 ID 由两个数字创建,并用“_”分隔,这就是我将使用 .split

的原因

这是我的代码

$('.done_by').each(function()
{
    temp = $(this).attr('id').split("_");

    $.post("../functions/ajax/display_name.php",
    {
      id_case: temp[0],
      id_task: temp[1]
    },
    function(data,status){

        $(this).html(data);                 
        //alert("Data: " + data + "\nStatus: " + status);
    });             
});

id_caseid_task 已发送到 display_name.php。 我不确定 $(this).html(data);

的语法

什么也没显示。但警报(数据)发送了我想要的一切。我几乎可以肯定语法是错误的

最佳答案

“this”对象是它自身的当前函数。 替换如下。

$('.done_by').each(function()
{
  temp = $(this).attr('id').split("_");
  var self = this;

  $.post("../functions/ajax/display_name.php",
  {
    id_case: temp[0],
    id_task: temp[1]
  },
  function(data,status){

    $(self).html(data);                 
    //alert("Data: " + data + "\nStatus: " + status);
  });             
});

关于javascript - 在 Ajax 循环中添加文本功能已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29213717/

相关文章:

javascript - Ajax - 将 JSon 渲染为 HTML : View vs Controller

javascript - 有 Angular ;错误: Component NewPharmacyComponent is not part of any NgModule or the module has not been imported into your module

javascript - Angular.js 和 ng-switch-when - 模拟枚举

javascript - 网络音频 api : How to increase continuously the volume of the sound from the beginning

php - WP 编辑器 - wp_editor() 在 ajax 调用上未正确显示

jQuery .ajax() 调用失败

javascript - jQuery 在不同的单选按钮组中选择单选按钮索引

javascript - React - 变量未定义而不是 true/false - 组件首先呈现?

jquery - 何时使用 html.beginform 与 ajax.beginform

javascript - 需要一种方法从许多相同元素之一获取 attr