weixin_33725807 2012-07-29 02:18 采纳率: 0%
浏览 24

AJAX使数据保持刷新

I currently have a like button that now works with Ajax. With one minor flaw. I click like on a post and it updates 1 like and shows in the page. But if I refresh the page it vanishes out of sight. The like is still in the database it just doesn't show in the page. Now someone told me to use

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

to do this on page load, but I have no clue how to use it to make my likes show on page refresh. Or maybe I have to make a new call on page refresh to get all the likes for each post.

This is what I have so far

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>";
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条