如何使以下代码被AJAX调用,即,单击链接以更新数据库,并在浏览器中更新页面而不重新加载它?
<?php
$server = "localhost";
$user = "root";
$pass = "";
$database = "test";
mysql_connect($server, $user, $pass) or die ("check mysql settings");
mysql_select_db($database) or die ("database not found");
$data = mysql_query("SELECT * FROM settings ");
while ($row = mysql_fetch_array($data)) {
$images = $row["images"];
if($images == "yes") {
echo "<a href='index.php?img=no'>Do not show images on this site</a>";
} else {
echo "<a href='index.php?img=yes'>Show images on this site</a>";
}
}
$img = $_GET["img"];
if ($img == "yes") {
mysql_query("update settings set images='yes'");
} else {
mysql_query("update settings set images='no'");
}