Reputation: 2169
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?
Upvotes: 1
Views: 56
Reputation: 1237
Your URL is incorrect:
url: 'path/to/item.php&var1='+var1,
Use this instead:
url: 'path/to/item.php?var1='+var1,
Upvotes: 1
Reputation: 27802
In your item.php
file, you need to echo the result. Something like this:
echo $data;
rather than:
return $data;
Upvotes: 0