javascript - Text generated by php to span -
i have function (php) generates text, let say:
function a() { echo 'test'; }
next, have (html):
<span id="content"></span>
then, have (javascript):
fillobjectcontent = function(object, content) { $(object).html(content); }
and now, how can put text function js+jquery function? (or way). mean in php using:
echo "<script>fillobjectcontent('#content', 'test content')";
what should put in place of 'test content'?
assuming want call javascript fillobjectcontent
function , set value of #content
element using returned/echoed value of php function(after page loaded), can use ajax:
var fillobjectcontent = function(url, selector) { $.ajax({ url, url, type: 'get', }).done(function(returneddata) { $(selector).html(returneddata); }) } fillobjectcontent('urlstring', '#content');
note echo
ing javascript codes hackish, can json_encode
value , store in javascript variable.
Comments
Post a Comment