cmazur Posted August 15, 2007 Share Posted August 15, 2007 Hey Guys, I'm having trouble getting the correct values back to my webpage. I'm using PHP and JavaScript along with SAJAX. The value of the text that is getting set in the label on my html page is "undefined". Here's the code. Javascript: function getText_cb(getText) { document.getElementById("lblText").innerHTML = getText; } Php: function getText() { echo "This is the text"; } Any ideas? Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/65117-solved-using-ajaxphpjavascript/ Share on other sites More sharing options...
php_tom Posted August 15, 2007 Share Posted August 15, 2007 Try: <?php function getText(){ echo "This is the text"; } ?> <script type='text/javascript'> function getText_cb(getText) { document.getElementById("lblText").innerHTML = '<?php getText(); ?>'; } </script> I think the problem is that javascript interprets getText as a variable, which hasn't been defined in JS yet, so it's value is undefined. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/65117-solved-using-ajaxphpjavascript/#findComment-324988 Share on other sites More sharing options...
cmazur Posted August 15, 2007 Author Share Posted August 15, 2007 php_tom, What you've said seems to work, however, this gets away from using AJAX (the Sajax toolkit). I believe the syntax should've been right because I've used code similar before. Any other ideas? Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/65117-solved-using-ajaxphpjavascript/#findComment-325021 Share on other sites More sharing options...
cmazur Posted August 16, 2007 Author Share Posted August 16, 2007 Suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/65117-solved-using-ajaxphpjavascript/#findComment-325706 Share on other sites More sharing options...
php_tom Posted August 16, 2007 Share Posted August 16, 2007 Sry, not too familiar with ajax type codes here... maybe you can teach me! Quote Link to comment https://forums.phpfreaks.com/topic/65117-solved-using-ajaxphpjavascript/#findComment-325755 Share on other sites More sharing options...
cmazur Posted August 16, 2007 Author Share Posted August 16, 2007 Javascript: function getText_cb(getText) { document.getElementById("lblText").innerHTML = getText; } Php: function getText() { echo "This is the text"; } I figured it out. The problem was that I didn't have the right syntax when I was trying to call the callback function (getText_cb). The call should've been x_getText(getText_cb) instead of getText_cb(); If my function getText()took arguments, then then syntax would look like this: x_getText(arg1, arg2, getText_cb); Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/65117-solved-using-ajaxphpjavascript/#findComment-326101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.