【发布时间】:2012-03-28 10:05:12
【问题描述】:
我正在使用下面的脚本代码根据用户单击按钮时的按钮 ID 从我的数据库中获取结果。数据库结果以我正在测试的输出形式 alert(msg) 正常返回。有人可以帮助我如何在模式窗口中返回结果吗?我正在为使用bootstrap-modal.js 的应用程序使用引导程序,但我不知道如何集成这两个脚本。
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$('.ajax-link').click( function() {
$.get( $(this).attr('href'), function(msg) {
alert(msg);
});
return false; // don't follow the link!
});
});
});
</script>
引导模式调用示例:
<script>
$(function() {
$('#userGuide').modal({
backdrop: true;
});
});
</script>
更新:这是页面上的代码,我试图根据单击的按钮的 ID 使用 $.get 返回用户#userGuide:
<?php
//MySQL Database Connect
require 'config.php';
$id = $_GET["id"];
$stmt = $dbh->prepare('CALL sp_get_recipe_items(:id)');
$stmt->bindParam(':id',$id,PDO::PARAM_INT,4000);
$res = $stmt->execute();
if ($res){
while( $row = $stmt->fetchObject() ){
echo "<div id='userGuide' class='modal hide fade'><div class='modal-body'>".$row->Ingredient." ".$row->Quantity." ".$row->UoM." </div></div>";
}
}else{
$arr = $sth->errorInfo();
echo "Execution failed with MYSQL: " . $arr[0] . "\n";
die();
}
?>
【问题讨论】:
标签: jquery ajax modal-dialog twitter-bootstrap