Solved

json append to second select

Posted on 2014-03-28
2
269 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
Comment Utility
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
Comment Utility
listItems.messages was the key thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now