jquery给出Uncaught TypeError:非法调用

时间:2016-01-11 09:01:36

标签: javascript php jquery ajax

所以我试图在ajax的帮助下加载数据,它显示我这个错误 未捕获的TypeError:非法调用 我认为主要的错误是因为我的php文件我没想到任何方法将我的数据库值提供给我的like.php文件

jquery的

JavaScript的:

<script>
function validatelike(like)
{
    $.post("like.php",{like: like},function(data)
            {
            $("#echoresult").html(data)
            })
}
$("#newlike'.$mypostid.'").click(function()
        {
        validatelike($("#newlike'.$mypostid.'"));
        });
</script>

like.php

<?php
ob_start();
session_start();

if(isset($_SESSION['id']) && !empty($_SESSION['id']))
{
    $id=$_SESSION['id'];
    foreach($id as $msg)

}

if(isset($_GET['id']))
{
    $getid=$_GET['id'];

}

$seepostquery="select * from posts where addedbyid='$getid' ORDER BY id DESC";
$seequeryresult=mysqli_query($connection30,$seepostquery);

while($seequeryrow=mysqli_fetch_array($seequeryresult))
{
    $mypostid=$seequeryrow['id'];
    if(isset($_POST['like'])) {

        $queryselector=mysqli_query($connection30,"select * from likes where postid='$mypostid'");
        $resultselector=mysqli_fetch_array($queryselector);
        $likes=$resultselector['likes'];
        $likedby=$resultselector['addedby'];
        $likedbyexplode=explode(",",$likedby);
        $dislikes=$resultselector['dislikes'];

        if($likes=="" && $likedby=="" && $dislikes=="")
        {
            $queryinsert=mysqli_query($connection30,"insert into likes values('','$mypostid','1','$dislikes','$msg')");
        }
        if($likes!="" && $likedby!="")
        {
            $queryinsert=mysqli_query($connection30,"update likes set addedby=CONCAT(addedby,',$msg'),likes=likes+1 where postid='$mypostid'"); 
        }
    };

    $queryselect=mysqli_query($connection30,"select * from likes where postid='$mypostid'");
    while($rowselect=mysqli_fetch_array($queryselect))
    {
        $countlikes=$rowselect['likes'];
        $countdislikes=$rowselect['dislikes'];
        $likepercentage=($countlikes/($countlikes+$countdislikes))*100;
        echo ceil($likepercentage).'% people liked this';
    }
?>

1 个答案:

答案 0 :(得分:2)

您的PHP代码在语法方面无效。

例如:

if(isset($_SESSION['id']) && !empty($_SESSION['id']))
{
    $id=$_SESSION['id'];
    foreach($id as $msg)
    //                 ^^^^^ loop has no body

}

第一个while块似乎也没有关闭。 请使用IDE或一些基本语法高亮显示器来查找此类错误并重新格式化代码(在PhpStorm中按Ctrl + Alt + L / Cmd + Alt + L)。