ajax error when calling from javascript

Posted by vikitor on Stack Overflow See other posts from Stack Overflow or by vikitor
Published on 2010-03-18T11:00:43Z Indexed on 2010/03/18 12:01 UTC
Read the original article Hit count: 492

Hi, I' still newby to this so I'll try to explain what I'm doing. Basically what I want is to load a dropdownlist depending on the value of a previous one, and I want it to load the data and appear when the other one is changed. This is the code I've written in my controller:

public ActionResult GetClassesSearch(bool ajax, string phylumID, string kingdom){
  IList<TaxClass> lists = null;
  int _phylumID = int.Parse(phylumID);
  int _kingdom = int.Parse(kingdom);
  lists = _taxon.getClassByPhylumSearch(_phylumID, _kingdom);
  return Json(lists);
}

and this is how I call the method from the javascript function:

function loadClasses(_phylum) {
  var phylum = _phylum.value;
  $.getJSON("/Suspension/GetClassesSearch",
      { ajax: true,
      classID: phylum,
      kingdom: kingdom },
      },
      function(data) {
       $('#sClass').attr("disabled", true);
       $('#sClass').selectOptions("-2");
       $('#sClass').removeOption(/./);
       var values = '';
       $('#sClass').addOption("-2", "-Select All-");
       for (i = 0; i < data.length; i++) {
         $('#sClass').addOption(data[i].RecId, data[i].TaxonName);
       }
       $('#sClass').selectOptions("-2");
       $('#sClass').removeAttr("disabled");
     });  }

I can't get it to work. Any tips?

Thanks in advance

© Stack Overflow or respective owner

Related posts about c#

Related posts about JavaScript