dimanche 5 juin 2016

Embed PHP script output in javascript file

file1.php will echo the URL of the WordPress post featured image. I am trying to embed this URL in img tag in the file2.js file.

file1.php

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<?php echo $url ?>

file2.js

var mjvfiurl;
$.get("/wp-content/plugins/mjv_sample_plugin/file1.php", function(mjvdata) {
     mjvfiurl=mjvdata;
});

var fapDom = '<div id="fap-wrapper"><img src="'+mjvfiurl+'" alt="" /></div>';

$('body').append(fapDom);

But its not working. Source code rendered as below:

<img src="undefined" alt="">

Console error:

http://ift.tt/24qTocl 404 (Not Found)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire