0

当我单击用户链接上的共享时..它可以很好地共享该帖子,但它会发布两次。我检查了萤火虫,当点击(一次)时,它会显示两个 POST 请求,将两个帖子插入数据库,然后在用户提要中显示它们。我真的不明白我要去哪里错了。

分享链接

echo'<a class="sharelink" title="Share '.$poster_name['fullusersname'].'s status" href="#"
 data-streamitem_creator='.$streamitem_data['streamitem_creator'].'
 data-streamitem_target='.$_SESSION['id'].'
 data-streamitem_content='.$streamitem_data['streamitem_content'].'
 data-streamitem_type_id=4>Share</a>';

AJAX

$(document).ready(function() {
    $('.sharelink').click(function(e) {
        e.preventDefault();
        var streamitem_creator = $(this).data('streamitem_creator');
        var streamitem_target = $(this).data('streamitem_target');
        var streamitem_content = $(this).data('streamitem_content');
        var streamitem_type_id = $(this).data('streamitem_type_id');

        $.ajax({
            type: "POST",
            url: "../include/share.php",
            data: {
                streamitem_creator: streamitem_creator,
                streamitem_target: streamitem_target,
                streamitem_content: streamitem_content,
                streamitem_type_id: streamitem_type_id
            },
            success: function(data) {
                $(".usermsg").html(data);
            }
        });
    });
});​

分享.php

<? 
session_start();
require"load.php";

if(isset($_POST['streamitem_type_id'])&isset($_POST['streamitem_creator'])&isset($_POST['streamitem_content'])&isset($_POST['streamitem_target'])){

user_core::create_streamitem(4,$_SESSION['id'],$_POST['streamitem_content'],1,$_POST['streamitem_creator']);

}
?>

加载.PHP

public function create_streamitem($typeid,$creatorid,$content,$ispublic,$targetuser){
    global $mysqli;
            $content = $content;
//          $content =  strip_tags($content);

            if(strlen($content)>0){

    $insert = "INSERT INTO streamdata(streamitem_type_id,streamitem_creator,streamitem_target,streamitem_timestamp,streamitem_content,streamitem_public) VALUES ($typeid,$creatorid,$targetuser,UTC_TIMESTAMP(),'$content',$ispublic)";
            $add_post = mysqli_query($mysqli,$insert) or die(mysqli_error($mysqli));
            $last_id  = mysqli_insert_id($mysqli); 
                if(!($creatorid==$targetuser)){
                    $fromuser= rawfeeds_user_core::getuser($creatorid);
                    $_SESSION['id']==$content;
            }       
            return;
            }else{
            return false;
            }
4

1 回答 1

0

我看不出任何问题.. 无论如何,您没有$('.sharelink').click在您的页面中两次注册该处理程序吗?

于 2012-08-22T20:32:24.520 回答