我使用jquery ajax将远程文件中的动态数据加载到bootstrap中:
JS:
$(function(){
$('.push').click(function(){
var essay_id = $(this).attr('id');
$.ajax({
type : 'post',
url : 'your_url.php', // in here you should put your query
data : 'post_id='+ essay_id, // here you pass your id via ajax .
// in php you should use $_POST['post_id'] to get this value
success : function(r)
{
// now you can show output in your modal
$('#mymodal').show(); // put your modal id
$('.something').show().html(r);
}
});
});
});
HTML:
<a href="#" id="1" class="push">click</a>
<div class="modal-body">
<div class="something" style="display:none;">
// here you can show your output dynamically
</div>
</div>
这对我来说很有效,但模式框在加载/挂起数据之前不会显示。我需要加载模式框点击后,然后加载数据。
怎么解决这个问题?!
发布于 2015-12-15 07:54:00
您可以在加载时在单击事件之外进行ajax调用,并在单击时显示隐藏:
$(document).ready(function() {
var essay_id = $(this).attr('id');
var results;
$.ajax({
type : 'post',
url : 'your_url.php',
async: false
'post_id='+ essay_id,
success : function(r) {
results = r;
}
});
$(' your_element').click(function() {
if (results) {
$('#mymodal').show();
$('.something').show().html(results);
}
});
});
使用async:false将强制它在继续执行脚本之前完成您的请求。希望这能有所帮助。
https://stackoverflow.com/questions/34272617
复制相似问题