Is it okay to use PHP inside a jQuery script?

前端 未结 7 1356
误落风尘
误落风尘 2021-02-20 03:56

For example:

$(document).ready(function(){
    $(\'.selector\').click(function(){
        
    });
});
         


        
7条回答
  •  忘了有多久
    2021-02-20 04:33

    you have a better choice to use ajax that runs the php script when you are handling a click event

    $(document).ready(function(){
        $('.selector').click(function(){
           $.ajax({url:"phpfile.php",type:"POST",
    data:"datastring="+value+"&datastring2="othervalue,
    
    ,success:function(data){
    //get the result from the php file after it's executed on server
    }
    
    });
        });
    });
    

提交回复
热议问题