سؤال

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->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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top