无法将php数据返回到jQuery ajax调用

时间:2012-04-11 01:14:34

标签: php ajax jquery

似乎这类问题之前已被问过并回答过很多次,但即使经过几个小时尝试不同的事情,我也似乎无法实现这一点。

这是我的ajax:

$.ajax({
type: 'POST',
url: 'scripts/manageHomePage.php',
//datatype: 'json',
data: dataString,
cache: false,
success: function(response) {
    //$.parseJSON(response);

    alert('response: ' + response);
    //alert('Got a successful return: ' + response.result);
    //window.location.href="documents/" + response.result;
},
error: function(response) {
    alert ('There was an error creating the archive: ' + response);
}
});

正如你所看到的,我也一直试图用json来做这件事。这是返回数据的PHP代码:

if ($zipArchive) {
$log->lwrite('passing to ajax function: ' . $archiveName);
//$return['error'] = true;
//$return['result'] = $archiveName;
return $archiveName;
} else {
$log->lwrite('Error creating zip file - not passed to form');
//$return['error'] = false;
//$return['result'] = 'There was an error creating the zip file';
return 'error';
}

再次,json的更多尝试。无论如何,php脚本返回的变量$ archiveName是正确的。我在$ .ajax的success参数中的js警告显示“response:”

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您需要echo支持该功能的回复,而不是return