我想創建使用基於groupId數據庫的網格。目前,我已經調用了相同的查詢。我的問題是當我選擇一個組並使用jQuery
發佈到我的Gateway.php
文件。我創建了一個psuedo-MVC
設置。我在控制器,模型和視圖中分隔了3個目錄。從這個PHP文件,我不斷收到以下錯誤消息:php jquery致命錯誤:require():無法打開需要
Warning: require(Membership/Controllers/Members.php): failed to open stream: No such file or directory in H:\xampp\htdocs\HelloWorld\Membership\Includes\Gateway.php on line 11
Fatal error: require(): Failed opening required 'Membership/Controllers/Members.php' (include_path='.;H:\xampp\php\PEAR') in H:\xampp\htdocs\HelloWorld\Membership\Includes\Gateway.php on line 11
所以,我已經試過幾件事情。其一,我把這個調用移動到index.php上,它運行得很好。但是從jQuery
調用中,它給了我錯誤。
我創建了另一個PHP文件,其中包含一個函數。我從模型和視圖中移動了我的代碼。我讓它返回表格的html和結果。有用。
有人可以指向一個例子,使jQuery
ajax調用類函數嗎?或者給一些方向。
Members.js
var Members = {
Display: function(groupId) {
var pData = {
action: 'GetMembers',
groupId: groupId
};
$("#crGroups").empty();
$("#crGroups").append("Getting Members...");
$.ajax({
url: "Membership/Includes/Gateway.php",
type: "POST",
data: pData,
cache: false,
success: function (data, status, xhr) {
try {
var members = $.parseJSON(data);
if (members !== undefined) {
$("#crGroups").empty();
$("#crGroups").append(members.html);
} else {
$("#crGroups").empty();
$("#crGroups").append(data);
}
} catch (err){
$("#crGroups").empty();
$("#crGroups").append(data + "<br><br>Error description: " + err.message);
}
}
});
}
}
Gateway.php
<?php
$action = $_POST['action'];
$groupId = $_POST['groupId'];
$data = array();
// Gateway for processing
switch($action) {
case 'GetMembers' :
require 'Membership/Controllers/Members.php';
$member = new MembersController();
//include 'Members.php';
$data["status"] = "success";
$data["html"] = $member->GetMembers();
//$data["html"] = getMembers();
break;
case 'AddMember' :
$page = 'Add Member';
break;
case 'page3' :
$data["status"] = "success";
break;
case 'page4' :
$data["status"] = "success";
break;
default :
$data["status"] = "failure";
}
echo json_encode($data);
?>
url:「Membership/Includes/Gateway.php」..我認爲這將是錯誤的,因爲你在這裏使用僞mvc所以把這裏的網址將會訪問你的網頁Gateway.php ....喜歡「http:// yourDomain/xyz ..」我也被困在這樣的問題..和這樣的工作解決了它..希望它也適用於你.. – alwaysLearn 2013-03-16 05:18:40