Is it okay to use PHP inside a jQuery script?

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

For example:

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


        
7条回答
  •  离开以前
    2021-02-20 04:34

    PHP is executed on the server, and then the javascript will be executed on the client. So what you'd be doing here is using php to generate javascript that will become the function body. If that's what you were trying to do then there's nothing wrong with doing it.

    If you thought you were going to invoke some PHP code from javascript, then you're on the wrong track. You'd need to put the PHP code in a separate page and use an ajax request to get the result.

提交回复
热议问题