0

I am facing an issue while getting html response from ajax. My ajax response contains an html element having "onclick" attribute, when I removed the onclick I have got the response else it is showing me 500 Internal Server Error.

Phtml File code example (Ajax):

 jQuery( window ).load(function() {
            var temp_quote =jQuery('#quote-list-data').val();
            var compare =jQuery('#compare-data').val();
            var loadcollect = jQuery('#machine-key').val();
            var presentData = jQuery('#parent-class-data').val();
            var catData = jQuery('#cat-data').val();

            jQuery.ajax({
                url: "<?php echo Mage::helper('adminhtml')->getUrl('attr/employee/getListing'); ?>",
                type: "POST",
                data: {
                    temp_qquote_list: temp_quote,
                    compare_product: compare,
                     loadcollect: loadcollect,
                    presentData: presentData,
                    catData:catData
                },
                dataType: 'html',
                success: function (response) {
                    console.log("Success Ajax ");
                    jQuery(".similar_data").append(response);

                }
            });
        });

function showCompareLink(id, classname, link)
{
--------- code stmt ----------
}

Controller File Code Example:

public function getListing()
{
    $listData = '';
        $compare_product = ($_POST['compare_product']);

    foreach ($_productCollectionData as $_product) {
          $entity_id = $_product->getId();

    $listData .='<div class="below_compare">';
            if($_product->isSaleable())
            {
                 if (in_array($entity_id, $compare_product) && count($compare_product) >= 2) {
                    $addto_class = 'after_compare_checkbox_new_' . $_product->getId();
                    $addto_display = 'none';
                    $compare_display = 'block';
                 } else {
                     $addto_class = 'before_compare_checkbox_new_' . $entity_id;
                     $addto_display = 'block';
                     $compare_display = 'none';
                 }

                 if (in_array($entity_id, $compare_product)) {
                     $ckhed =  'checked';
                 } else {
                     $ckhed = '';
                 }
                $showCompareLinkParam = 'new';
                $compareUrlForAnchor = Mage::getUrl('catalog/product_compare/index');

                $onclickCompare = 'window.open("'.$compareUrlForAnchor.'", "_blank", "location=yes,height=720,width=720,toolbar=no,menubar=no,scrollbars=yes,resizable=yes")';
                $_compareUrl = $obj->helper('catalog/product_compare')->getAddUrl($_product);
                $listData .='<span class="addto">
                <input class="'.$addto_class.' onclick="'.showCompareLink($entity_id,this.className,$showCompareLinkParam).'" type="checkbox"'. $ckhed .' />
                <div style="display:'.$addto_display .'"
                     class="before_add_machine_to_compare_'.$mach_type.'_'.$entity_id.'">'. $obj->__('Compare').'</div>
                <div style="display:'. $compare_display .'"
                     class="after_add_machine_to_compare_' . $mach_type . '_' . $entity_id.'"> <a
                        class="compare_page_link"
                        **onclick**="'.$onclickCompare.'">'.$obj->__('Go to compare').'
                 </a></div>
            </span>';
            }
            $listData .='</div>';
    }
    echo $listData;
} 

Your Answer

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

Browse other questions tagged or ask your own question.