Inline javascript is separated from the AJAX response by the JS Ajax.Request prototype method

I am working on a Magento store trying to encode a javascript layer of a widget using a prototype js framework.

In my grid.js file, the AJAX call is configured as follows:

loadTabContent: function(tab, tabType){

        if(tab === undefined || tabType === undefined){
            return this;
        }

        entityId = tab.id.split('-')[3];

        request = new Ajax.Request(
            this.tabContentLoadUrl,
            {
                method:'get', 
                onSuccess: this.onTabContentLoad.bind(tab),
                onFailure: this.ajaxFailure.bind(this),
                evalJS: true,
                parameters: {
                    id: entityId, 
                    type: tabType
                }
            }
        );
    }

The following is a success handler:

onTabContentLoad: function(transport){

        if(transport && typeof transport.responseText !== undefined){
            try{
                response = transport.responseText;
            }catch (e) {
                console.log('PARSE ERROR', e);
                response = {};
            }

            entityId = this.id.split('-')[3];
            tabType = this.id.split('-')[1];

            if(response && $('tab-' + tabType + '-' + entityId + '-contents')){
                $('tab-' + tabType + '-' + entityId + '-contents').update(response);    
            }
        }
    },

The content for the div is updated correctly by calling AJAX, but there is some built-in JS in response that does not work. I don’t even see this javascript fragment on the Elements tab (Chrome developer tool)

Below is the code that processes the server side AJAX request:

public function renderTabContentAction()
    {
        $entityId = Mage::app()->getRequest()->getParam('id');
        if( ! $entityId){

            $this->getResponse()->setHeader('HTTP/1.0', '400', true);
            $this->getResponse()->setBody('Invalid parameters provided.');
        }

        $tabType = Mage::app()->getRequest()->getParam('type');
        if( ! $tabType){

            $this->getResponse()->setHeader('HTTP/1.0', '400', true);
            $this->getResponse()->setBody('Invalid parameters provided.');
        }

        Mage::register('current_entity_id', $entityId);
        Mage::register('current_tab_type', $tabType);

        $tabHtml = $this->_getTabsHtml($entityId, $tabType);    


        $this->getResponse()->setHeader('HTTP/1.0', '200', true);
        $this->getResponse()->setBody($tabHtml);
    }

The following is the response that is passed to the onTabContentLoad AJAX handler:

 <div class="vertical-tabs">
      <div class="tabs">
        <div class="tab" id="tab-vertical-137-2441">
          <input type="radio" id="label-vertical-product-tab-137-2441" name="product-tab-group-137">
          <label class="tabs-label" for="label-vertical-product-tab-137-2441">PG-10ml</label>
          <div class="content" id="tab-vertical-137-2441-contents">
          </div>
        </div>
        <div class="tab" id="tab-vertical-137-2442">
          <input type="radio" id="label-vertical-product-tab-137-2442" name="product-tab-group-137">
          <label class="tabs-label" for="label-vertical-product-tab-137-2442">PG-15ml</label>
          <div class="content" id="tab-vertical-137-2442-contents">
          </div>
        </div>

      </div>
    </div>
   <script type="text/javascript">
     bulkOrderGrid.initVerticalTabs();
     bulkOrderGrid.activateTab('2441', 'VERTICAL');
   </script>

, SCRIPT . , Element.update, SCRIPT. , .

: Ajax.Updater evalScripts: true Ajax.Request evalJS: true.

. .

:

Element.update . prototype.js №. 2048. , js-. js-, SCRIPT . stripScripts .

   else {
     element.innerHTML = content.stripScripts();
   }

   content.evalScripts.bind(content).defer();
+1
2

, , Ajax String#evalScripts(), , script

<script type="text/javascript">
 window.bulkOrderGrid.initVerticalTabs();
 window.bulkOrderGrid.activateTab('2441', 'VERTICAL');
</script>

, - transport.responseText.evalScripts(), window. script, .

0

Element.update() script. Element.innerHTML

0

All Articles