Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 根据ajax api请求多次插入数据库_Php_Jquery_Mysql_Ajax - Fatal编程技术网

Php 根据ajax api请求多次插入数据库

Php 根据ajax api请求多次插入数据库,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我正在建立一个社交网站。我的喜欢/不喜欢注释功能有问题。每当单击like/discoke按钮时,like计数通常会更新,但我在comment\u likes/discokes表中得到多个插入,这会导致通知表中出现多个插入(对于所有帖子ID)。我假设这个bug是由jQueryAjax调用API引起的。我错在哪里?下面是我的个人资料页面javascript和comment_likes api(类似于comment_dislikes)。我甚至配置了posts和comments api来返回合并的JSO

我正在建立一个社交网站。我的
喜欢/不喜欢注释功能有问题。每当单击
like/discoke
按钮时,like计数通常会更新,但我在
comment\u likes/discokes
表中得到多个插入,这会导致通知表中出现多个插入(对于所有帖子ID)。我假设这个bug是由jQueryAjax调用API引起的。我错在哪里?下面是我的个人资料页面javascript和comment_likes api(类似于comment_dislikes)。我甚至配置了posts和comments api来返回合并的JSON posts和comments,但没有成功。我需要加载每个评论下面的具体职位…职位喜欢/不喜欢的功能运作良好

$(文档).ready(函数(){
$.ajax({
键入:“获取”,
url:“../api/profile发布旧的?用户名=”,
processData:false,
contentType:“应用程序/json”,
数据:“”,
成功:功能(r){
var posts=JSON.parse(r);
$。每个(职位、职能(索引){
//从数据库加载内容
$('.timelineposts').html(
$('.timelineposts').html()++'公开共享-'+posts[index].PostDate+''+posts[index].PostBody+'

      • ); }); //允许用户喜欢评论 $(“[data comlid]”)。单击(函数(){ var buttonid_two=$(this.attr('data-comlid'); $.ajax({ 类型:“POST”, url:“../api/comment likes?comid=“+$(this).attr('data-comlid')+”&postid=“+buttonid, processData:false, contentType:“应用程序/json”, 数据:“”, 成功:功能(r){ var res=JSON.parse(r); $(“[data comlid='”+buttonid_two+“']”).html(“”+res.Likes); 控制台日志(r); }, 错误:函数(r){ 控制台日志(r); } }); }); //允许用户不喜欢评论 $(“[data comdid]”)。单击(函数(){ var buttonid_three=$(this.attr('data-comdid'); $.ajax({ 类型:“POST”, url:“../api/comment dislikes?comid=“+$(this).attr('data-comdid')+”&postid=“+buttonid, processData:false, contentType:“应用程序/json”, 数据:“”, 成功:功能(r){ var res=JSON.parse(r); $(“[data comdid=”+buttonid_three+“]”).html(“+res.Dislikes”); 控制台日志(r); }, 错误:函数(r){ 控制台日志(r); } }); }); }, 错误:函数(r){ 控制台日志(r); } }); //允许用户喜欢帖子 $(“[data id]”)。单击(函数(){ var buttonid=$(this.attr('data-id'); $.ajax({ 类型:“POST”, url:“../api/post likes?id=“+$(this).attr('data-id'), processData:false, contentType:“应用程序/json”, 数据:“”, 成功:功能(r){ var res=JSON.parse(r); $(“[data id=””+b