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

Edited by Ishangarg61
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.