假设我列出了一个具有如下链接的行列表:
content.php
/*DATABASE CONNECTION AND SQL STUFF*/
<div id='content'>
<?php
$sql = mysql_query ("SELECT id, somedata FROM myTable");
while ($row = mysql_fetch_assoc($sql)) {
echo "<a href='?p=moreData&id=" . $row['id'] . "'>" . $somedata . "</a><br />\n";
}
?>
</div>moreData.php
<?php
$id = $_GET['id'];
/* SQL STUFF */
echo "More information about" . " ". $somedata. " " . "wich has an id of" . " " . $id;如何使用moreData.php在文件content.php中加载名为<div id='ajaxContent'>的新div中的$_GET信息,而不是加载新页面?
我读过一些关于jQuery加载的文章,但是我对jQuery编码非常陌生,我自己也搞不懂.
发布于 2012-05-29 15:12:04
您需要预置一个javascript,其中包含要通过GET到moreData.php发送的id。我会将它设置为rel属性为标记,并在处理click事件时获取它。
echo "<a class='ajaxCall' rel='" . $row['id'] . "' href='?p=moreData&id=" . $row['id'] . "'>" . $somedata . "</a><br />\n";然后单击事件
$('a.ajaxCall').click(function() {
var rowId = $(this).attr('rel');
}); 在同一事件中,ajax调用
$.ajax({
type: "get",
url: '/moreData.php', // your uri to the moredata
data: { id: rowId },
success: function(data) { // data is the response of the ajax call
$('#ajaxContent').html(data);
}
}); 你需要jQuery库。
https://stackoverflow.com/questions/10801768
复制相似问题