【问题标题】:Assign values from responseText to textbox using extjs使用 extjs 将值从 responseText 分配给文本框
【发布时间】:2012-11-22 07:17:29
【问题描述】:

我正在使用 EXTjs 并尝试通过 ajax 连接到服务器并以 xml 格式获取输出。有 3 个文本框需要填充这些 xml 值

response.responseText 给了我结果,但是 response.responseXML 给了 null。是否有任何方法可以将 responseText 转换为 responseXML,然后将值分配给文本框。 有人可以帮帮我吗?

function getXML(){
    Ext.Ajax.request({
            url : 'url',
            params  : {
                   method   : 'runxml'
                },
            method  : 'POST',
            success : function(response, options) {
                alert(response.responseXML);
                alert(response.responseText);       

            },
            failure : function(response, options) {
                Ext.MessageBox.show({
                    title   : 'Error On retrieve value from server',
                    msg : 'An error occur during retrieve value from server',
                    buttons : Ext.MessageBox.OK,
                    icon    : Ext.MessageBox.ERROR,
                    width   : 400
                    });
                },
                disableCaching  : true
            });
            }

}

我从 response.responseText 得到的输出是

<wddxPacket version='1.0'><header/>
<data><string>&lt;?xml version="1.0" encoding="iso-8859-1" ?&gt;
<char code='0a'/>&lt;TABLE&gt;
<char code='0a'/>&lt;LIMITS&gt;
<char code='0a'/>&lt;UCL&gt; 5.23145 &lt;/UCL&gt;
<char code='0a'/>&lt;CTL&gt; 3.0269 &lt;/CTL&gt;
<char code='0a'/>&lt;LCL&gt; 1.458&lt;/LCL&gt;
<char code='0a'/>&lt;/LIMITS&gt;
<char code='0a'/>&lt;/TABLE&gt;
<char code='0a'/></string></data></wddxPacket>

【问题讨论】:

    标签: extjs


    【解决方案1】:

    您是否将 HTTP 响应中的 Content-Type 标头设置为“text/xml”或“application/xml”。因为浏览器要解析返回的 XML 文档,HTTP 响应中的 Content-Type 标头必须设置为“text/xml”或“application/xml”。这非常重要——否则 XmlReader 将无法正常工作。

    【讨论】:

    • 使用 firebug 我可以看到响应内容类型为 text/html。我无权访问服务器,因此无法将其设置为 text/xml。对此还有其他选择吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    相关资源
    最近更新 更多