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
Casey Dwayne
2,1691 gold badge17 silver badges33 bronze badges
2 Answers 2
Your URL is incorrect:
url: 'path/to/item.php&var1='+var1,
Use this instead:
url: 'path/to/item.php?var1='+var1,
answered Jul 10, 2013 at 16:22
Petr R.
1,2372 gold badges23 silver badges33 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Petr R.
Nevermind, I just learned about echos in jsFiddle.
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
jh314
27.9k16 gold badges66 silver badges83 bronze badges
1 Comment
Casey Dwayne
It is echo, as stated in OP. True return will not work for the ajax.
default