Jquery Function is saying not defined when running a php script

前端 未结 3 1445
悲&欢浪女
悲&欢浪女 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:24

    Why not use jQuery instead of inline JS? Give your div's classes:

    ...

    Then use jQuery instead of onclick() as it would be much cleaner:

    $(document).on('click', '.voteup', function(){
        var clientid = $(this).data('clientid');
        $.get("voteup.php", { clientid: clientid });
        return false;
    })
    

    Since you're already using jQuery this will help you to keep your markup cleaner, giving you the freedom to make changes much more easily to your markup and your JavaScript.

    In addition, this will remove scoping issues so that you do not have to add namespaces.

    The only other problem I see is that you're not passing $_POST['clientid'] to voteup.php, so your query will never run. You can include data-client-id in your div declaration but you will have to change your test in your PHP to be:

    if (isset($_GET['clientid'])) 
    

    As you would be sending the value along wwith a GET request.

提交回复
热议问题