1

I'm having trouble returning data from a php page.

test = function(data){
 alert(data);
}
newContent = function(var1){
 $.ajax({
 url: 'path/to/item.php&var1='+var1,
 success: function(data){
 test(data);
 }
 });
}

Which should return "Success" via echo 'Success!'; on the item.php page.

Why is it returning undefined?

asked Jul 10, 2013 at 16:17

2 Answers 2

1

Your URL is incorrect:

url: 'path/to/item.php&var1='+var1,

Use this instead:

url: 'path/to/item.php?var1='+var1,

JsFiddle here

answered Jul 10, 2013 at 16:22
Sign up to request clarification or add additional context in comments.

1 Comment

Nevermind, I just learned about echos in jsFiddle.
0

In your item.php file, you need to echo the result. Something like this:

echo $data;

rather than:

return $data;
answered Jul 10, 2013 at 16:19

1 Comment

It is echo, as stated in OP. True return will not work for the ajax.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.