我在应用程序中实现Ext.Direct时遇到问题。我已经按照documentation中的教程进行了操作,但没有让它起作用。
问题在于它总是在我的所有调用中返回Invalid request
,这表示$HTTP_RAW_POST_DATA
和$_POST['extAction']
都未设置。
router.php
...
if(isset($HTTP_RAW_POST_DATA)) {
header('Content-Type: text/javascript');
$data = json_decode($HTTP_RAW_POST_DATA);
} else if (isset($_POST['extAction'])) { // form post
$isForm = true;
$isUpload = $_POST['extUpload'] == 'true';
$data = new Action();
$data->action = $_POST['extAction'];
$data->method = $_POST['extMethod'];
$data->tid = isset($_POST['extTID']) ? $_POST['extTID'] : null; // not set for upload
$data->data = array($_POST, $_FILES);
} else {
die('Invalid request.');
}
...
POST值如下:
{
"action": "viewResourceParticulars",
"method": "getResults",
"data": [
{
"page": 1,
"start": 0,
"limit": 25,
"group": [
{
"property": "groupField",
"direction": "ASC"
}
],
"sort": [
{
"property": "groupField",
"direction": "ASC"
}
]
}
],
"type": "rpc",
"tid": 1
}
我已经检查了我的php.ini,而always_populate_raw_post_data
选项是true
,但仍然无效。所以我现在没有想法。
任何帮助表示感谢。
用于调用Ext.Direct的代码:
的index.php
$cs->registerScriptFile($baseUrl.'/js/direct/api.php');
api.php返回
Ext.ns("Ext.app"); Ext.app.REMOTING_API = {"url":"js\/direct\/router.php","type":"remoting","actions":{"viewResourceParticulars":[{"name":"getResults","len":1}]}};
Ext.data.Store
...
proxy: {
type: 'direct',
directFn: viewResourceParticulars.getResults
},