我想使用jQuery ajax方法获取一些数据。这里是我的代码:jquery appendTo函数不工作里面的Ajax成功函数
$('body').on('click','.showSlots', function() {
var screen_Id = $(this).attr('id');
//alert(screen_Id);
$.ajax({
url:base_url+'admin/movies/getScreenSlots',
type:'post',
data: {screen_Id:screen_Id},
success: function(result)
{
result = $.parseJSON(result);
//$('.screenList1,.screenList12').empty();
$.each(result, function(key, element)
{
$('<tr class="screenList1"><td><input required name="slotName" type="text" placeholder="enter slot"><input name="screen_id1" required type="hidden" value="'+element.screen_id+'" class="screen_ids1"></td><td><input required name="movieName" type="text" placeholder="Movie Name"></td><td><input required name="rate" type="text" placeholder="rate"></td></tr>').appendTo($(this).closest('table'));
});
}
});
});
成功从数据库获取数据。和jQuery的'每个'功能运作良好。但'appendTo'功能不起作用。尝试了很多浏览器。但同样的问题。请帮忙。谢谢。
你能展示你的html吗? – Saurabh
当您在.each函数中引用'this'时,它会引用正在循环的数组中的当前项目。 –
嗨@Sean Wessell那是个问题!!问题现在已修复,非常感谢Sean Wessell .. – user3706231