【问题标题】:Ext JS: How to return xml from a php's curl call to extjs proxy in Store?Ext JS:如何将 xml 从 php 的 curl 调用返回到 Store 中的 extjs 代理?
【发布时间】: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>

谢谢,如果有不清楚的地方请告诉我。

【问题讨论】:

  • 我什至尝试将代理类型设置为“休息”,但不幸的是没有结果..

标签: php xml extjs proxy store


【解决方案1】:

尝试在您的 php 脚本中设置标题 像这样:

<?php
.
.
.
$html = curlCall($my_endpoint);
header("Content-type: text/xml");
echo $html;
?>

【讨论】:

  • 工作!!!我错过了这个,还修复了我的 php 文件上的一个小语法错误!非常感谢!!
【解决方案2】:

您是否尝试将响应标头设置为 XML?

header('Content-type: text/xml');echo $html; 之前,因为如果响应与其他内容类型一起发送,ExtJS 的 XML 阅读器不会将响应识别为 XML。

【讨论】:

    猜你喜欢
    • 2012-01-08
    • 2013-05-06
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多