0

I have this function:

public function adminhtmlWidgetContainerHtmlBefore($event)
{
    $blockID = Mage::app()->getRequest()->getParam('id');
    $js = "<script type='text/javascript'>
                jQuery.ajax({
                        url: '".Mage::helper('adminhtml')->getUrl('adminhtml/index/generate/')."', 
                        method: 'GET', 
                        data: {FeedId : ".$blockID."}}).success(function(){
                            alert ('Generation Successful!'); 
                            }).error(function(){
                                alert ('Generation Failed!'); 
                });
        </script>";
    $block = $event->getBlock();
    $test= Mage::getModel('test/test')->getCollection();
    if($test)
    {
        foreach($test as $currentFeed)
        {
            if($blockID == $currentFeed->getData('id'))
            {
                $link = $currentFeed->getData('filename');
                $block->addButton('Download', array(
                    'label'     => Mage::helper('adminhtml')->__('Download'),
                    'onclick'   => "window.open('http://test.com".$link."', '_blank', 'Download')"
                ), -1);
                $block->addButton('Generate', array(
                    'label'     => Mage::helper('adminhtml')->__('Generate Feed'),
                    'onclick'   => $js,
                    'class'     => 'go'
                ), -1);
            }
        }   
    }
}

And I am getting an error when I try to click the Generate button, the error is:

(index):646 Uncaught SyntaxError: Unexpected token <

And I am not sure why, the problem is with my $js value, but it seems correct, what could actually cause this error? I know it is something simple but I can not figure it out.

Thank you.

0

Have you tried concatenating the string, or assigning the values one by one?

You also need to echo the values in PHP.

public function adminhtmlWidgetContainerHtmlBefore($event)
{
$blockID = Mage::app()->getRequest()->getParam('id');


$js = "<script type='text/javascript'>
        jQuery.ajax({
                    url: '". echo Mage::helper('adminhtml')->getUrl('adminhtml/index/generate/'); . "', 
                    method: 'GET', 
                    data: {FeedId : ". echo $blockID . "}}).success(function(){
                        alert ('Generation Successful!'); 
                        }).error(function(){
                            alert ('Generation Failed!'); 
            });
    </script>";
$block = $event->getBlock();
$dreamAgility = Mage::getModel('dreamagility/dreamagility')->getCollection();
if($dreamAgility)
{
    foreach($dreamAgility as $currentFeed)
    {
        if($blockID == $currentFeed->getData('id'))
        {
            $link = $currentFeed->getData('filename');
            $block->addButton('Download', array(
                'label'     => Mage::helper('adminhtml')->__('Download'),
                'onclick'   => "window.open('http://dreamagilityshop.com".$link."', '_blank', 'Download')"
            ), -1);
            $block->addButton('Generate', array(
                'label'     => Mage::helper('adminhtml')->__('Generate Feed'),
                'onclick'   => $js,
                'class'     => 'go'
            ), -1);
        }
    }   
}

}

1
  • Yes, it is not working with concatenating or echo – DanteZ Oct 6 '16 at 10:34
0

Solved!

I created a script function after the php and the problem was that the js files were not loading.

<script type='text/javascript'>
jQuery.noConflict();

function generateFeed(feedId) {
    jQuery.ajax({
        url: "<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/index/generate/') ?>", 
        method: 'POST', 
        data: {FeedId : feedId}
    }).success(function() {
        alert ('Generation Successful!'); 
    }).error(function() {
        alert ('Generation Failed!'); 
    });
}

I just called this function and it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.