【发布时间】:2014-02-23 07:55:25
【问题描述】:
我是 ExtJs 和 Web 技术的新手,我这几天想做的是从我的 php 文件中获取响应,该文件向服务器 api 发出 curl 请求,并返回一个 xml 格式对象。当我将此对象单独存储在 xml 文件中并将 ExtJs 商店的代理设置为
proxy: {
type: 'ajax',
url: 'app/apiCalls/data_suites.xml',
autoload: 'true',
autoSync: 'true',
reader: {
type: 'xml',
root: 'data_suites',
record: 'data_suite'
}
}
..它将数据加载到存储中,但是当我将代理更改为返回相同对象的.php文件时,它无法加载数据。
这是我的 .php 文件,带有示例 xml 返回:
$my_endpoint = XXXXXXX //myendpoint defined here
function curlCall($my_url){
$header[] = 'Content-Type: application/x-www-form-urlencoded';
//initializing curl object
$curl = curl_init();
//adding fields to the curl object to enter the site
curl_setopt($curl, CURLOPT_URL, $my_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 40);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
//executing the curl call and getting data back
$html = curl_exec($curl);
curl_close($curl); // close the connection
return $html;
}
$html = curlCall($my_endpoint);
echo $html;
//even tried returning as simple xml object but didnt work
//$xml = new SimpleXMLElement($html);
//echo $xml
我只在我的商店代理中更改了这一行来尝试接收 .php 输出
url: 'app/apiCalls/data_suites.php',
这是我的示例“data_suites.xml”,这与我的浏览器显示的 php 返回为 $html 的内容相同。
<?xml version="1.0" encoding="UTF-8"?>
<data_suites>
<data_suite id="6">
<name>Test</name>
<description>Test Described</description>
</data_suite>
<data_suite id="8">
<name>Another Test</name>
<description>Another Test Described</description>
</data_suite>
</data_suites>
谢谢,如果有不清楚的地方请告诉我。
【问题讨论】:
-
我什至尝试将代理类型设置为“休息”,但不幸的是没有结果..