Solved

json append to second select

Posted on 2014-03-28
2
270 Views
Last Modified: 2014-03-28
Trying to append data to another dropdown after response from jquery data. but for some reason it is not displaying or get and error object

Response after selection from Getmyweek.  Json
{"messages":[{"Week":7},{"Week":8},{"Week":14}]}

Open in new window


 
<select id="Getmyweek">
          <option selected="selected">-- Please Select --</option>
  <option> week 7-</option>

      </select>
<select id="GetWeek">
      </select>

Open in new window


$("#Getmyweek").change(function () {

              
                var Id = $("#Getmyweek").val();
                $.ajax({
                    url: '@Url.Action("getcontroller", "Viewer")',
                type: "Post",
                data: { Chain1: Id },
                success: function (listItems) {
                    $.each(listItems, function (i, item) {
                        $('#GetWeek').append($('<option>').text(this.Week).attr('value', item));
                    });

                    // var toAppend = '';
                    //    $.each(listItems, function (i, item) {
                    //    toAppend += '<option>' + item + '</option>';
                    //   // alert(toAppend);
                    //});
                        $('#GetmyWeek').append(toAppend).html;
                 
                },
                error: function (xhr, ajaxOptions, error) {
                    alert(xhr.status);
                    alert('Error: ' + xhr.responseText);
                }

            });

             });

Open in new window

0
Comment
Question by:sevensnake77
2 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 39962170
I think you want this

$.each(listItems.messages, function (i, item) {
   $('#GetWeek').append($('<option>').text(item.Week).attr('value', item));
});
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39962291
listItems.messages was the key thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now