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 echoing javascript codes hackish, can json_encode value , store in javascript variable.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -