Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it okay to use PHP inside a jQuery script?

For example:

$(document).ready(function(){
    $('.selector').click(function(){
        <?php
        // php code goes here
        ?>
    });
});

Will this cause issues or slow down the page? Is this bad practice? Is there anything important that I should know related to this?

Thanks!

like image 796
hellomello Avatar asked Jun 22 '11 05:06

hellomello


1 Answers

If you are trying to bound some PHP code with the click event then this is impossible in the way you are trying and PHP code will be executed as soon as page load without waiting for a click event.

If you are trying to generate final javascript or jquery code using PHP then this is okay.

like image 143
Shakti Singh Avatar answered Oct 02 '22 12:10

Shakti Singh