Home > Mobile >  How to embed php in javascript?
How to embed php in javascript?

Time:03-15

Face problem when writing PHP syntax in javascript syntax.

var id = $("#data-1").val();
var url = '<?= base_url('home/alone/'); ?>.'id'';
console.log(url);

I need to place the id at the end of url. But my code is not working. What is wrong? Thank you in advance.

CodePudding user response:

use " instead of ' like this:

var id = $("#data-1").val();
var url = "<?= base_url('home/alone/'); ?>"   id;
console.log(url)
  • Related