差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
java:web:ext:xmlparser [2013/07/12 22:33] tony |
java:web:ext:xmlparser [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 22: | 行 22: | ||
<code xml> | <code xml> | ||
<result> | <result> | ||
- | <status>success</status> | + | <status>false</status> |
- | <msg></msg> | + | <msg>Validation failed.</msg> |
</result> | </result> | ||
</code> | </code> | ||
行 29: | 行 29: | ||
一般正規的原始做法如下: {{:java:web:ext:example_xml_parser.zip|Download Sample}} | 一般正規的原始做法如下: {{:java:web:ext:example_xml_parser.zip|Download Sample}} | ||
<code javascript> | <code javascript> | ||
- | var text = "<result><status>success</status><msg>test msg</msg></result>"; | + | var text = "<result><status>false</status><msg>test msg</msg></result>"; |
var xmlDoc = null; | var xmlDoc = null; | ||
行 67: | 行 67: | ||
}); | }); | ||
</code> | </code> | ||
- | 在這存取資料的Proxy使用了memory的type。以往都是使用Ajax的方式取得後端資料讓reader做處理,但因為我們已取得Server回傳的資料,所以需存取的是local的變數: response.responseXML。 | + | 在這存取資料的Proxy使用了memory的type。以往都是使用Ajax的方式取得後端資料讓reader做處理,但因為我們已取得Server回傳的資料,所以需存取的是local的變數: response.responseXML。\\ |
+ | 首先透過Ext.create去產生ServerResponseStore的instance,接著透過loadRawData去讀取DOM Document,最後我們就可以透過getAt取得對應的record(result element)。拿到record後,我們就可以使用get去取得對應的內容了。 | ||
<code javascript> | <code javascript> | ||
success: function(response){ | success: function(response){ | ||
行 80: | 行 81: | ||
var status = result.get('status'); | var status = result.get('status'); | ||
if( status == 'false' ){ | if( status == 'false' ){ | ||
- | Ext.example.msg('Failed', msg); | + | window.alert('Failed:' + msg); |
} else { | } else { | ||
- | Ext.example.msg('Success', 'Send start command to client successfully.'); | + | window.alert('Execute command successfully.'); |
} | } | ||
} | } | ||
</code> | </code> | ||
+ | \\ | ||
+ | 友藏內心獨白: 寫ExtJS其實花的時間比寫一般Javasript還花時間! 可能還不夠熟悉吧! | ||
===== Reference ===== | ===== Reference ===== | ||
* [[http://javaclaus.wordpress.com/2010/10/12/extjs-xml-and-the-dom/|ExtJS, XML, and the DOM]] | * [[http://javaclaus.wordpress.com/2010/10/12/extjs-xml-and-the-dom/|ExtJS, XML, and the DOM]] | ||
* [[http://help.dottoro.com/ljssopjn.php|Dotoro - DOM Parser]] | * [[http://help.dottoro.com/ljssopjn.php|Dotoro - DOM Parser]] | ||
+ | |||
+ | ===== ===== | ||
+ | ---- | ||
+ | \\ | ||
+ | ~~DISQUS~~ |