0

我目前有一个赞按钮,现在可以与 Ajax 一起使用。有一个小缺陷。我在帖子上单击喜欢,它会更新 1 个喜欢并在页面中显示。但是,如果我刷新页面,它就会消失不见。类似的内容仍在数据库中,只是没有显示在页面中。现在有人告诉我使用

$(document).ready(function () {}

在页面加载时执行此操作,但我不知道如何使用它来让我的喜欢在页面刷新时显示。或者,也许我必须在页面刷新时重新调用才能获得每个帖子的所有喜欢。

这是我到目前为止所拥有的

function likestatus(postid,contextid){
var obj = document.getElementById(contextid);
$.post("../include/like_do.php", { streamitem_id: postid},function(data){
//see the parameter data in this function. Data contains whatever that you echo in your php file.
$("#likesprint"+postid).html(data+"Likes");
 });
}

Like_do.php

<?php
session_start();
require"load.php";
if(isset($_POST['streamitem_id'])){

$check = user_core::check_liked($_SESSION['id'],$_POST['streamitem_id'],1);

user_core::do_like($_SESSION['id'],$_POST['streamitem_id'],1);

echo $check; // as your user_core::check_liked() function returns number of likes.
}else{
echo "<script>alert('Error liking post');</script>";
}
?>
4

0 回答 0