开发者

Updating innerHTML with HTML from a php function? (using xajax)

开发者 https://www.devze.com 2023-02-13 16:19 出处:网络
I\'m successfully updating the innerHTML of a DIV through xajax (when I click a link) but only when I assign HTML in the function itself, not when I call it from a different function.

I'm successfully updating the innerHTML of a DIV through xajax (when I click a link) but only when I assign HTML in the function itself, not when I call it from a different function.

To explain

  // For the sake of testing
$output=rand(20,40);

  // Add new HTML to container through $output
$ajax_resp-&开发者_如何转开发gt;assign('div_container','innerHTML', $output);

return $ajax_resp;

This works fine. When I call this function through clicking the link, the container updates with a random number. However when I change $output to

$output=$compile->show('text');

Which is (simplified)

function show($var) { echo $var; }

It does not show it. The function show works perfectly outside of xajax. Any suggestions?


function show($var) { echo $var; }

This function doesn't return anything, it echo's the value to the screen. However, most functions you probably want to return a value, so they can work with it. Basically, when you do

$output=$compile->show('text');

It will get no input from the show method, because show doesn't return any value. I think if you change it to the following:

function show($var) { return $var; }

It will work.


Have you tried to change function show($var) { echo $var; } to function show($var) { return $var; }. Should solve your problem

0

精彩评论

暂无评论...
验证码 换一张
取 消