Using php includes in jquery

What I'm trying to do is use php includein the app attribute jquery. something like that:

$('a.popup[href^=#]').click(function() {
$('body').append('<div id="content" class="popup_block"><?php include( SITE_URL . 'activity/popup.php' ) ?></div>');

My script is in the php file, on the server side, so I could do it, but I'm not sure how to do it. When it comes to html, css, etc., I can combine it and php in a php file, but when it comes to javascript, its quotes confuse me, and when and how to use parentheses. This may seem strange. Anyway, does CDATA have anything to do with this? I have never used it before, but I should at least study its use.

+3
source share
2 answers

PHP <?php ?> - . . , , PHP, Javascript.

var foo = '<?php include 'foo.php'; ?>';

var foo = 'This is the content of foo.php.';

PHP .

foo.php , :

var foo = 'This is the 'content' of foo.php.';

Javascript. foo.php, , addslashes. , .

JSON, :

var foo = <?php echo json_encode("Some string with 'quotes'."); ?>;

, , JSON XML.

+4

100% , - , , .

, php append(). , . , .

+1

Source: https://habr.com/ru/post/1783540/


All Articles