3

I am calling webmethod to populate select tag. success return but does not populate select options

here is my call

function getCities(country2) {
        $.ajax({
            type: 'POST',
            url: 'getCities.aspx/getCitiesArray',
            contentType: 'application/json; charset=utf-8',
            dataType: "json",
            data: "{countryName:'" + (country2) + "'}",
            success: function (msg) {
                alert(msg);
                $("#city").empty().append($("<option></option>").val("[-]").html("select city"));
                $("#city").append($("<option></option>").val("Other").html("Not in the List"));
                var htm = "";
                $.each(msg.d, function () {
                    $("#city").append($("<option></option>").val(this['Value']).html(this['Text']));
                });
            },
            error: function () {
                alert("Ajax Error");
            }
        });


and the webmethod in Visual studio 2005. ASP.NET 2.0

[WebMethod]
        public static ArrayList getCitiesArray(string countryName)
        {
            ArrayList emptyArrayList = new ArrayList();
            string sql = "select ISNULL(CityName,'-') as CityName, ISNULL(CityCode,1) as CityCode from ListCities where CountryID = (select ISNULL(CountryID,0) from ListCountries where CountryName = '" + countryName + "')";
            DataTable dtCities = new DataTable();
            dtCities = DBUtils.GetDataTable(sql);
            ArrayList lstArrCities = new ArrayList();
            if ((dtCities != null) && (dtCities.Rows.Count > 0))
            {                
                for (int i = 0; i < dtCities.Rows.Count; i++)
                {
                    lstArrCities.Add(new ListItem(dtCities.Rows[i]["CityName"].ToString(), dtCities.Rows[i]["CityCode"].ToString()));                    
                }                                
                return lstArrCities;
            }
            return emptyArrayList;
        }
3
  • 4
    You're STILL using Visual studio 2005 with ASP.NET 2.0? Really?????? Commented Jun 10, 2014 at 10:08
  • Take a look at this question and the answer I wrote stackoverflow.com/questions/18244696/… as well as the question linked in the comments. Commented Jun 10, 2014 at 10:10
  • 1
    What is the value of msg when it comes back from the AJAX call? Commented Jun 11, 2014 at 11:00

1 Answer 1

0

I'd suggest you spend some more time on debugging your code to find the source of the problem. NArrow it down the cause of the problem to client or server first. For example:

  1. What is the value of msg when it comes back from the AJAX call? If it's NULL or something unexpected stop looking at the client side and dig into the server side code before re-attacking the front end.
  2. What does your SELECT SQL return when you run it external to the application? If it's not returning any data you need to go even deeper into your database and work on the data side.

The answer to your problem is going to be very difficult to determine based on the code you've pasted - especially without your data.

Break it down into it's constituent parts and only then carry on building. Good luck.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.