Jump to content

Call PHP Output in JS?


Ishangarg61

Recommended Posts

Hello ,
i am facing issue in js and php, please help me,
i have create one php file and put the

<script>ex.ui{"name": "<?php echo for ( esc_attr ( get_option ( 'sclm ) ) ); ?>",}</script>

like above script.
But i want to put that script in js file. but when i am use that script in js file, then that php code creating problem. so how to get solve that issue.

I want that script in js, and that php code will be fetch the value in js. so please help me about that.

Thanks

Link to comment
Share on other sites

Store the value from php into a hidden input field

<?php

$hidden_content = "Hello World";                                            // CREATE HIDDEN CONTENT
?>   
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="mytest.js"></script>
</head>
<body>
    <input type="hidden" id="my-hidden" value="<?=$hidden_content?>">        <!-- STORE HIDDEN CONTENT -->
</body>
</html>

In your js file, get the value from the hidden input

    $().ready( function() {
        
        alert( $("#my-hidden").val())
        
    })

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.