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?

4

2 回答 2

1

您的网址不正确:

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

改用这个:

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

JsFiddle在这里

于 2013-07-10T16:22:53.683 回答
0

在您的item.php文件中,您需要回显结果。像这样的东西:

echo $data;

而不是:

return $data;
于 2013-07-10T16:19:28.917 回答