新手:Ext.decode做什么?

问题描述 投票:4回答:2

我有一个功能:

function openOpportunityHome() {

    showSpinner("Loading.Please wait ");
    Ext.Ajax.request({
                url : contextPath + '/OpportunityTracker.do',
                method : 'POST',
                params : {
                    'role' : SALES_TRACKER_ROLE
        },
                success : function(response, request) {
                    hideSpinner();
                    MD_opportunityMasterDataVO = Ext
                            .decode(response.responseText);
                    ADMIN_OPP_LIST_FLAG =MD_opportunityMasterDataVO.adminOppListFlag;
                    showOpportunitySearch();

                },
                failure : function(response, request) {
                    hideSpinner();
                    ajaxFailureCallbackFn(response, request);
                }
            });
   }

当我打电话给Ext.decode(response.responseText)时,究竟发生了什么?请从请求/响应范围的角度讲述。

extjs extjs3
2个回答
6
投票

Ext.decode()只是一个类似于JSON.parse()的JSON解析器,它将一串文本解析为您可以在Javascript中访问的对象。

它实际上是Ext.JSON.decode()的别名。

您可以在ExtJS文档中阅读有关here的更多信息。


1
投票

您可以使用3种方法来解析响应。

  1. 浏览器默认方法:JSON.parse()
  2. Ext方法:Ext.JSON.decode()简写Ext.decode()

基本上response.responseText将采用String格式。解码后,它将成为一个对象。如果响应为null,则decode方法将引发错误。

© www.soinside.com 2019 - 2024. All rights reserved.