1

i have a select field set that triggered AJAX script when onchange, the ajax is calling the controller with post data, but i got an error saying

loader.js:41 Uncaught TypeError: url.match is not a function

here's the code:

$k = Mage::getSingleton('core/session')->getFormKey();
$event = $fieldset->addField(
            'category_id',
            'select',
            array(
                'label'  => Mage::helper('test_sellercenter')->__('Category '),
                'name'   => 'category',
                'values' => Mage::helper('test_sellercenter/dropdown')->getLazadaCategories(),
                'class' => 'required-entry lazadacat',
                'onchange'  => 'checkSelectedItem(this)',
                'container_id' => 'categoryId'
        ));

        $event->setAfterElementHtml("<script type=\"text/javascript\">
          function checkSelectedItem(selectElement){
              new Ajax.Request({
                url: '".$this->getUrl('test_sellercenter/Adminhtml_MassActions/attributeslazada')."',
                type: 'POST',
                data: {category: selectElement.value, form_key:'".$k."'},
                success: function(data) {
                          console.log(data);
                        }
              });

          }
      </script>");

1 Answer 1

0

My AJAX function is a mess, i fix the ajax and it runs well now

here's the AJAX code:

$event->setAfterElementHtml("<script type=\"text/javascript\">
          function checkSelectedItem(selectElement){
              var url = '". $this->getUrl('test_sellercenter/Adminhtml_MassActions/attributeslazada')."';
              var category = selectElement.value;
              new Ajax.Request(url, {
                parameters: {isAjax: 1, method: 'POST', data1:category},
                onSuccess: function(data) {
                   if(data.responseText != 'Failed'){
                     console.log(data.responseText);
                   }
                }
              });
          }
      </script>");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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