【发布时间】:2016-07-18 22:52:22
【问题描述】:
我有一个模式,我在元素点击时显示它。 所以我想通过Ajax更新这个模式中的输入值,我可以成功检索数据但它不会正常更新它的值(获取其他文章记录的值而不是当前articleID),这里是我的代码:
$('#editArticle').on('show.bs.modal', function (e) {
...
$articleID = $(e.relatedTarget).attr('data-id');
$.ajax({
type: "GET",
url : 'article/'+ $articleID +'/getData',
dataType : "json",
success : function(data){
document.getElementById("serial").value = data['serial'];
}
});
});
如果我将警报设置为显示数据,它会返回正确的值:
success : function(data){
alert(data['serial']); // here it returns the right value for each row, and it appears after the modal show !!!!
document.getElementById("serial").value = data['serial'];
}
【问题讨论】:
-
为什么不使用点击事件监听器?
-
您能发布
data中的内容吗?还有什么目的是使用jquery然后为document.getElementById恢复到JS?为什么不使用 jQuery 选择器?:$("#serial").val(data['serial']); -
@BKF。其他可能性,检查 id
serial是否是唯一的,在整个页面中,或者可能存在拼写错误或将其更改为不同的内容并检查。 -
你能用 jsfiddle 或 codebin 准备一个复制问题的演示,让我们看看吗?
标签: javascript jquery ajax twitter-bootstrap laravel-5.1