-1

I want to send base_url from Controller Book to book.js

This is my function in book.js

function loadPage(page, pageElement) {

    // Create an image element
    var img = $('<img />');

    img.mousedown(function(e) {
        e.preventDefault();
    });

    img.load(function() {
        // Set the size
        $(this).css({width: '100%', height: '100%'});

        // Add the image to the page after loaded
        $(this).appendTo(pageElement);

        // Remove the loader indicator
        pageElement.find('.loader').remove();
    });

    // MY PROBLEM is here !!! Load the page
    // img.attr('src', '../../_library/book/samples/magazine/pages/' +  page + '.jpg');
    img.attr('src', '<?php echo base_url($source) ?>' +  page + '.jpg');

    loadRegions(page, pageElement);

}
1

1 Answer 1

1

You cannot use php commands in js files. But instead you can define a variable between script tags in the php file. For example:

example.php

<script>
const EXAMPLE_VAR = '<?php echo base_url($source);?>'
</script>

And you can use it in js file like this:

img.attr('src', EXAMPLE_VAR +  page + '.jpg');
Sign up to request clarification or add additional context in comments.

1 Comment

Thank's emrez. Your suggestion solve my problem.

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.