Mahesh
Mahesh

Reputation: 1593

How to pass a value from PHP to Javascript without using Ajax?

I need to pass the version no to javascript from php. But i dont want to use ajax.

$(document).ready(function(){
    init();
})

<body>
...
<input type="hidden" id="version" value="<?php echo $version; ?>
....

<script>
function init() {
   version = $('#version').val();
}
</script>

Can i do in this way? Or, should i use ajax?

Upvotes: 0

Views: 41

Answers (1)

Jonas Wilms
Jonas Wilms

Reputation: 138267

If you do so theres no need to put it into a hidden input:

const version = "<?php echo $version; ?>";

Upvotes: 3

Related Questions