dpv21589 2019-02-28 20:38
浏览 88

将Base64从PHP转移到Javascript

First of all I'm new here and new in the programming business. :)

So my problem:

I have Base64 images witch are stored in a database. Now i am selecting the data with PHP but i need the Data in Javascript. Without the Base64 images it's no problem to transfer the data from PHP to Javascript with following Code:

PHP:

require "Controller.php"; $controller = new Controller; $data= $controller->getData();

Javascript:

var data = <?php echo json_encode($data); ?>

And now my question: How do i transfer base64 code from PHP to Javascript? Or is there another way to use the Images in javascript if they are in a MySQL Database?

I hope someone can help me here. Thanks :D

  • 写回答

2条回答 默认 最新

  • duanping2695 2019-02-28 20:46
    关注

    This should do:

    btoa(atob(data))
    

    See btoa and atob.

    评论

报告相同问题?