Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 28, 2013 09:49 AM by iluxa.v
Member
118 Points
425 Posts
Jan 28, 2013 05:51 AM|LINK
Hi,
My code for cascade dropdownlist
Here is my code
<script type="text/javascript"> $(document).ready(function () { $(function () { $('#AgencyId').change(function () { var Aid = $(this).val(); Level1---------------------------- $.getJSON("ContactList\getDepartment", { Aid: Aid }, function (k) { var Account = $('#DepartmentId'); alert(Account); Account.empty(); Account.append($('<option/>', { value: 0, text: "Select Account " })); $.each(k, function (index, city) { Account.append($('<option/>', { value: city.value, text: city.text })); }); }); }); }); });
Until level1 code is working, But after this
$.getJSON("ContactList\getDepartment", { Aid: Aid }, function (k) {
code not working
Here is my action
public ActionResult getDepartment(int Aid) { int AgencyTypeId = db.Agencys.Where(x => x.Id == Aid).SingleOrDefault().AgencyTypeId; return Json( db.Departments.Where(x => x.AgencyTypeId == AgencyTypeId).OrderBy(x => x.Description).Select(x => new { value = x.Id, text = x.Description }), JsonRequestBehavior.AllowGet ); }
where is the issue?
All-Star
86665 Points
9634 Posts
Moderator
MVP
Jan 28, 2013 09:40 AM|LINK
First off, your URL looks wrong. Use a forward slash instead.
$.getJSON("ContactList/getDepartment", { Aid: Aid }, function (k) {
Use the IE Debugging tools to see what error response you are getting (such as 404 not found, or 500 error). Just press F12 in Internet Explorer.
215 Points
47 Posts
Jan 28, 2013 09:49 AM|LINK
What exactly not working?
It looks like you getting the data after you append the options, since the ajax request is async and it takes time.
Just try to add to your ajax request async:false and then try it.
Try to use $.ajax instead
$.ajax({ url: 'ContactList\getDepartment', dataType: 'json', async: false, data: JSON.stringify(Aid), success: function(data) { $.each(k, function (index, city) { Account.append($('<option/>', { value: city.value, text: city.text })); } });
gslakmal
Member
118 Points
425 Posts
My jquery code not working
Jan 28, 2013 05:51 AM|LINK
Hi,
My code for cascade dropdownlist
Here is my code
<script type="text/javascript"> $(document).ready(function () { $(function () { $('#AgencyId').change(function () { var Aid = $(this).val(); Level1---------------------------- $.getJSON("ContactList\getDepartment", { Aid: Aid }, function (k) { var Account = $('#DepartmentId'); alert(Account); Account.empty(); Account.append($('<option/>', { value: 0, text: "Select Account " })); $.each(k, function (index, city) { Account.append($('<option/>', { value: city.value, text: city.text })); }); }); }); }); });Until level1 code is working, But after this
$.getJSON("ContactList\getDepartment", { Aid: Aid }, function (k) {public ActionResult getDepartment(int Aid) { int AgencyTypeId = db.Agencys.Where(x => x.Id == Aid).SingleOrDefault().AgencyTypeId; return Json( db.Departments.Where(x => x.AgencyTypeId == AgencyTypeId).OrderBy(x => x.Description).Select(x => new { value = x.Id, text = x.Description }), JsonRequestBehavior.AllowGet ); }DarrellNorto...
All-Star
86665 Points
9634 Posts
Moderator
MVP
Re: My jquery code not working
Jan 28, 2013 09:40 AM|LINK
First off, your URL looks wrong. Use a forward slash instead.
$.getJSON("ContactList/getDepartment", { Aid: Aid }, function (k) {Use the IE Debugging tools to see what error response you are getting (such as 404 not found, or 500 error). Just press F12 in Internet Explorer.
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
iluxa.v
Member
215 Points
47 Posts
Re: My jquery code not working
Jan 28, 2013 09:49 AM|LINK
What exactly not working?
It looks like you getting the data after you append the options, since the ajax request is async and it takes time.
Just try to add to your ajax request async:false and then try it.
Try to use $.ajax instead
$.ajax({ url: 'ContactList\getDepartment', dataType: 'json', async: false, data: JSON.stringify(Aid), success: function(data) { $.each(k, function (index, city) { Account.append($('<option/>', { value: city.value, text: city.text })); } });