我正在尝试使用以下代码在 div 中加载 PHP 文件:
编辑器.php:
$con = mysqli_connect("","",","");
$result = $con->query("SELECT title,id FROM Development ")or die("Error! : ".$con->error);
while($row = $result->fetch_assoc())
{
echo "<a href='#' id='edit-it' onclick=\"load('".$row['id']."');\">". $row['title']. "</a><br>";
};
在 JavaScript 文件中:
function load(div,url)
{
$('#edit-it').load('#title_edit_div','edit_title.php');
}
在edit_title.php里面:
<?
$id=$_GET['id'];
$con = mysqli_connect("","","","");
$result = $con->query("SELECT title,content, FROM Development where id=".$id);
while($row = $result->fetch_assoc())
{
echo "<form action='" .$_SERVER['PHP_SELF']. "' method='get'> Title: <input type='text' name='title' value='",$row['title'],"><br>";
echo "Content: <input type='text' name='content' value='",$row['content'],"><br>";
echo "<input type='submit' value='Edit' name='change'></form>";
}
if(isset($_GET['change']))
{
$con->query("UPDATE Development SET title=".$_GET['title'].", content=".$_GET['content']." WHERE id=".$id.";");
}
?>
然后回到 editor.php:
echo "<div id='title_edit_div'></div>";
它只是行不通。当我检查源代码时,我得到的是:
<a id="edit-it" onclick="load('1');" href="#"></a>
如何在 div 中加载 PHP 文件?