troubleshooting Question

Need help parsing json table resprestentation with jQuery to HTML select options

Avatar of Drevo
DrevoFlag for United States of America asked on
JavaScriptASP.NETAJAX
3 Comments1 Solution409 ViewsLast Modified:
Hi Experts,

I'm performing an Ajax request using jquery's $.ajax against a .net web service. The service returns a serialized table result. I would like to use this result to populate a html select element. I ran across the following code for the success of the ajax request, though it doesn't appear correct:
success: function (data) {
                   for (i = 0; i < data.d.length; i++) {
                        ddlStates.append($("<option></option>").val(data.d[i].StateCode).html(data.d[i].StateName));
                   };
                }

My web service returns the following:
{"d":{"Columns":["StateID","StateName","StateCode","CountryCode"],"Rows":[[1,"Alabama","AL","US"],[43,"Arizona","AZ","US"],[3,"California","CA","US"],[7,"Florida","FL","US"],[46,"Georgia","GA","US"],[8,"Hawaii","HI","US"],[9,"Illinois","IL","US"],[10,"Indiana","IN","US"],[11,"Iowa","IA","US"],[18,"Michigan","MI","US"],[21,"Missouri","MO","US"],[26,"New Mexico","NM","US"],[49,"New York","NY","US"],[33,"South Carolina","SC","US"],[35,"Texas","TX","US"],[38,"Virginia","VA","US"],[39,"Washington","WA","US"],[41,"Wisconsin","WI","US"]]}}

Can you help in mapping this to the select element options?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros