سؤال

I have a function:

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);
                }
            });
   }

When I call Ext.decode(response.responseText), what exactly happens? Please tell from the perspective of a request/response Scope.

هل كانت مفيدة؟

المحلول

Ext.decode() is just a JSON parser similar to JSON.parse() and parses a string of text into objects you can access in your Javascript.

It's actually an alias for Ext.JSON.decode().

You can read more about it here in the ExtJS documentation.

نصائح أخرى

You can use 3 methods to parse the response.

  1. Browser default method: JSON.parse()
  2. Ext methods: Ext.JSON.decode() shorthand Ext.decode()

Basically response.responseText will be in String format. After its been decoded, it will be an object. If the response is null then decode method will throw an error.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top