Jump to content

[SOLVED] using ajax,php,javascript


cmazur

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.