How to send or assign Jquery Variable value to php variable?

前端 未结 3 2092
野趣味
野趣味 2020-12-21 06:29

I got the answer from this post [How to send or assign Jquery Variable value to php variable? but somehow my PHP can not get the value passed from Jquery
this is html co

3条回答
  •  不知归路
    2020-12-21 07:19

    Try this, you need to prevent onclick action to go to the that page.

    $(document).ready(function() {
        $("a").click(function() {
            $.ajax({
                type: "POST",
                url: "random.php",
                data: {"name" : $(this).attr('id')}
            }).done(function( msg ) {
               alert( "Data Saved: " + msg );
           });
        return false; // prevent from browsing that page
        });
    });
    

提交回复
热议问题