我有一个通过 ajax 提交的表单:
$(function() {
$(".submit").click(function() {
var listid = $("#listid").val();
var itemid = "<?=$id?>";
var userid = "<?=$_SESSION['user_id']?>";
var dataString = 'listid=' + listid + '&userid=' + userid + '&itemid=' + itemid;
$.ajax({
type: "POST",
url: "join.php",
data: dataString,
success: function(){
$('#content_error').fadeIn(200).show();
}
});
return false;
});
});
这完美地工作。ajax函数调用join.php:
<? session_start();
require_once("include/database.php");
$Db = new Database();
if($_POST['listid'] && $_POST['itemid'] && $_POST['userid']) {
$list_id = $_POST['listid'];
$user_id = $_POST['userid'];
$item_id = $_POST['itemid'];
$sql = "SELECT *
FROM items_list
WHERE list_id = '".$list_id."'
AND user_id = '".$user_id."'
AND item_id = '".$item_id."'
ORDER BY item_id DESC LIMIT 1";
$result = $Db->sQuery($sql);
$row = mysql_fetch_array($result);
if(mysql_num_rows($result) > 0){
$error = "You've already saved this";
}else{
$sql = "INSERT INTO items_list (list_id, user_id, item_id)
VALUES('$list_id', '$user_id', '$item_id')";
$Db->uidQuery($sql);
$sql = "SELECT count(item_id) as itemm
FROM items_list
WHERE item_id = '".$item_id."'
GROUP BY item_id";
$result = $Db->sQuery($sql);
$Db->closeConnection();
$tel2 = mysql_fetch_array($result);
?>
<span class="bubble_itemm"><?=$tel2['itemm']?></span>
<?
$success = "Sucessfully";
}
}
?>
成功后,我使用类bubble_itemm 调用span。这个跨度也存在于主页中。我希望“新”跨度用淡入淡出替换主页中的“旧”跨度。
我该怎么做呢?