我想使用 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_case 和 id_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/