Reputation: 19
I am new in PHP, i want to use "base_url"(php variable) in javascript file,But right now i am unable to load image,Here is my current code,How can i do this ? Thanks in advance.
$('#site-logo').find('img').attr( {src:'<?php echo base_url(); ?>assets/images/logo/[email protected]',width:'151',height:'45'} );
Upvotes: 1
Views: 91
Reputation: 146
You can create a variable or a constant in the javascript and store the base url there and use the same in the code.
Something along the line of following
var BASE_URL = "<?php echo base_url(); ?>";
$('#site-logo').find('img').attr({src: BASE_URL+'/assets/images/logo/[email protected]',width:'151',height:'45'});
Upvotes: 1