Jquery Function is saying not defined when running a php script

前端 未结 3 1406
悲&欢浪女
悲&欢浪女 2021-01-25 02:12

I am essentially making it so when you click on a button to \"vote up\"

at the moment i have

clients.php



        
3条回答
  •  一个人的身影
    2021-01-25 02:17

    Why do I get an error in the console saying "ReferenceError: voteUp is not defined"

    Scope.

    The voteUp() and voteDown are defined in the startup block (within the {} of $(document).ready(function() ... so are not available outside this block.

    You need to move the two functions outside:

    $(document).ready(function() {
        ...
    });
    
    function voteUp()
    {
        $.get("voteup.php");
        return false;
    }
    
    function voteDown()
    {
        $.get("votedown.php");
        return false;
    }
    

提交回复
热议问题