我有一個腳本,可以從數據庫中的相關類別加載頁面時從數據庫加載樣本圖像。從數據庫結果創建JSON對象使用AJAX post方法回發到jQuery UI對話框
<?php
$category = 'granite';
$samples = 'SELECT * FROM material WHERE material_type = :cat';
$res = $db->prepare($samples);
$res->execute(array(':cat' => $category));
$count = $res->rowCount();
if($count > 0)
while ($row = $res -> fetch()){
$postimggranite = $row[mat_image];
$postidgranite = $row[id];
?>
<?php
echo "<div class='sample'>";
echo "<h3 class='sample_h'>$row[name]</h3>";
echo "<a href='/images/granite-worktops/samples/$postimggranite'><img src='/images/granite-worktops/thumbs/$postimggranite' alt='$row[name]' width='100' height='100' class='aligncenter size-full' title='$row[name]'></a>";
echo "<br /><a class=\"button\" href=\" \" rel=\"nofollow\" onClick=\"user_notice(this,''); return false;\">More Details</a>";
echo "</div>";
}
?>
你可以從腳本中的最後一個回聲見上關閉一個div我有一個「更多詳細信息按鈕之前,通過點擊出現在我需要顯示的附加信息在屏幕上的對話框同樣DB。方法我打算用的是
function user_dialog(a,b){
"undefined"!=typeof jQuery.ui?($("#dialog").attr("title","Detailed Information").html(a),
$("#dialog").dialog({
modal:true,
width:400,
buttons: {
Cancel: function() {
$(this).dialog("close");
},
Download: function(){
$(this).dialog("close");
window.location=b
}
}
}
))
:window.location=b}
function user_notice(a){
download_link=$(a).attr("href");
$.ajax({
type:"POST",
url:"/includes/json.php",
data:"action=reminder&thepath="+download_link,
dataType:"json",
error:function(){
window.location=download_link
},
success:function(a){
1==a.status&&user_dialog(a.html,download_link);
}
})
};
這裏也是我的json.php文件
<?php
header('X-Robots-Tag: noindex, noarchive');
$a = session_id();
if(empty($a)) session_start();
if($_SERVER['HTTP_REFERER']){
$resp_dialog = array(
'status' => 1,
'html' => '<p>Here is you sample and rest of staff</p>'
);
echo json_encode($resp_dialog);
}else{
header('HTTP/1.1 403 Forbidden');
exit;
}
?>
清楚的腳本所有的工作和行<p>Here is you sample and rest of staff</p>
出現在對話框中,但我真正需要的是創建一個json對象,該對象帶來了來自數據庫的其他信息,並且不知道在json.php
文件的哪個位置,或者創建某種附加文件並將其放置在與urlid="something to get fromdb"
比$_GET['urlid']
json.php
發送它做DB。基本上不知道在什麼地方以及在哪裏做。
對我來說請放輕鬆,因爲我仍然在學習這一切,而且大部分對我來說還是很新的,所以請原諒我,如果我沒有正確解釋。
所以,基本上我必須把數據庫查詢腳本放在我的json.php,現在我明白了。讓我試試看,如果出現問題,我可能不得不回來。感謝您的建議 – AlexB
我試圖讓它工作,但看起來我無法正確構建更多信息按鈕的href。 – AlexB
我編輯了我的答案,添加了如何將id傳遞給json.php文件。然後,在該文件中,獲取id並創建你的sql。 – vinigarcia87