Wierd AJAX return

edited May 2012 in Modules
I am using AJAX to auto populate a Sub Categories select box, its contents depend on whats selected in the main Categories Select Box. It seems when I select a main Category and something is returned back, the Sub Category select vanishes and its replaced by an IFRAME of the homepage/index.php.

// INCLUDED IN THE MODULE CONFIG

'js_controller'=>'ProductController'

// THE ACTUAL ProductController.js

fuel.controller.ProductController = jqx.createController(fuel.controller.BaseFuelController, {
init: function(initObj){
this._super(initObj);
},

items : function(){
// call parent
fuel.controller.BaseFuelController.prototype.items.call(this);
//fuel.controller.BaseFuelController.prototype.items();
var _this = this;
$('#product_subcategory').change(function(e){
$('#form_table').submit();
});
},

add_edit : function(){
// call parent
fuel.controller.BaseFuelController.prototype.add_edit.call(this);
var origParentId = $('#product_subcategory').val();
var id = 5;
$('#product_category').change(function(e){
var category=$('#product_category').val();
category=category.replace(' ','_');
var path = jqx.config.basePath + '/products/getsubcat/' + category;
$('#product_subcategory').parent().load(path);
});
},

upload : function(){
this._notifications();
this._initAddEditInline($('#form'));
}
});

// THE MODEL

// Show Subcats
$fields['product_subcategory'] = array(
'label'=>'Product Subcategory',
'type'=>'select',
'options'=>$this->getsubcats($values['product_category'],$values['product_subcategory']),
'order' => '12'
);


// THE FUNCTION WITHIN THE MODEL

function getsubcats($cat,$sub) {
$subcats=array();
$q=$this->db->get_where('fuel_product_categories',array('category_name'=>$cat));
foreach($q->result() as $row) {
if($sub!=$row->subcategory_name) {
$subcats[$row->subcategory_name]=$row->subcategory_name;
}
}
$subcats[$sub]=$sub;
return $subcats;
}




All the ID's are set correctly in the fields!

Thanks

Comments

  • edited 1:58PM
    Are you able to navigate to jqx.config.basePath + '/products/getsubcat/' + category and have it return a result normally. Also, are there any javascript errors that appear in the console.
  • edited 1:58PM
    Are you able to navigate to jqx.config.basePath + '/products/getsubcat/' + category ??

    Sorry i dont understand...
  • edited 1:58PM
    Are you able to navigate to the url that path is parsed to EG: http://localhost/project/fuel/products/getsubcats/a_category
  • edited 1:58PM
    Ahh I see sorry, Ye it just redirects back to the root and shows the homepage.
  • edited 1:58PM
    Sounds like it might be routing problem.

    Any routes set that may redirect? I'm assuming you have a custom fuel controller of products with a getsubcats method? Can we see that?
Sign In or Register to comment.