0

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.

1
  • Too many single quotes and use + in JS to concatenate Commented Mar 15, 2022 at 7:38

1 Answer 1

2

use " instead of ' like this:

var id = $("#data-1").val();
var url = "<?= base_url('home/alone/'); ?>" + id;
console.log(url)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.