Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6890579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:18:01+00:00 2026-05-27T06:18:01+00:00

I am attempting to populate a dropdown based on the value selected in another

  • 0

I am attempting to populate a dropdown based on the value selected in another dropdown. I am using this guy’s example, but have not gotten it to run successfully yet. I have a successful Ajax call that is fired on the change event of the parent dropdown. I’ve verified that the data passed to the Ajax function is correct. However, the result is an error (200; unexpected character in JSON result). I’ve been trying to figure out how to debug the a) controller action that is called in the Ajax call and b) the function that feeds a list of results to the controller action. Can anybody help me figure out how to debug a) and b)? Visual Studio 2010 doesn’t offer a lot of help for debugging the targets of Ajax calls, it seems.

Here’s the code I have:

1) The controller action (BreedController) that calls a list helper class function to supposedly return a JSON object back to the Ajax successful callback.

    //
    // Retrieve JSON object containing breeds for a given species
    //
    [HttpPost]
    public JsonResult BreedsBySpecies(int? id)
    {
        ListHelper lh = new ListHelper();
        return Json(new { items = lh.GetBreedsBySpecies(id) }, JsonRequestBehavior.AllowGet);
    }

2) The function that should return a SelectItemList of breeds given a species ID. This is called by the controller action.

    public List<SelectListItem> GetBreedsBySpecies(int? speciesID)
    {

        var breed = from b in db.Breeds
                    select b;

        if (speciesID.HasValue)
        {
            breed = breed.Where(b => b.SpeciesID == speciesID);
        }

        List<SelectListItem> lst = new List<SelectListItem>();
        foreach (var item in breed)
        {
            lst.Add(new SelectListItem { Text = item.Description, Value = item.BreedID.ToString() });
        }

        return lst;
    }

3) The javascript function that does the Ajax call. I’ve confirmed that this is getting the right values (e.g., “/Breed/BreedsBySpecies” to get to the right controller action and formData contains the right species ID)

function selectFromAjax(url, formData, target) {
    $(target).html("");
    if (formData.id) {
        $.ajax({
            type: 'POST',
            url: url,
            data: formData,
            dataType: 'text json',
            contentType: 'application/json; charset=utf-8',
            success: function (data, textStatus) {
                if (data) {
                    $(data.items).each(function () {
                        $(target).append($("<option></option>").attr("value", this.Value).text(this.Text));
                    });
                    $(target).change();
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            }
        });
    }
    else {
        $(target).change();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:18:02+00:00Added an answer on May 27, 2026 at 6:18 am

    you should hit the break point if its making it that far. my guess is that you need to stringify your object to get the json .net is going to understand. or, since its such a simple object, just do something like:

     data: "{'id': '" + formData.Id + "'}"
    

    Edit

    since you are just passing in an id, you could technically just use the url to get where you want, passing no data at all. you’d just do something like this:

    url: url + '/'+ formData.Id
    

    this does tightly couple your routes and javascript, which isn’t ideal, but it gets the job done. and it removes the need to pass any data to the data parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this android calendar http://w2davids.wordpress.com/android-simple-calendar/ and attempting to populate it with events. In
Attempting to use the data series from this example no longer passes the JSONLint
I have a bit of a unique database structure but the query I'm attempting
i'm attempting to populate an array with random numbers, but the random numbers must
I'm attempting to populate a drop down from an Nhibernate object, but having problems
I'm attempting to populate a DB on my local SQL2008 Server using a Data
Using jquery 1.7.1, I'm using json to populate the dropdown. The code works just
I am attempting to populate a table based on 2 and 3 week intervals
I am attempting to create a DirectShow source filter based on the pushsource example
I am attempting to populate a list of records within the last X seconds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.