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

前端 未结 3 2086
野趣味
野趣味 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:13

    HTML:

    comp1
    comp2
    comp3
    

    JS:

    $('a').click(function(){        
        $.ajax({
            type: "POST",
            url: 'random.php',
            data: { name: $(this).attr('id') }
        })
        .done(function( msg ) {
            alert( msg );
        });
    });
    

    Use href="javascript:;" attr, or e.preventDefault(); inside event handler, to prevent the link executing.

提交回复
热议问题