Solved

json append to second select

Posted on 2014-03-28
2
272 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Animation faster 5 49
jQuery scrollTop 2 51
Weekend adv creator 3 39
jQuery Parallax 1 43
by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
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…
The viewer will learn how to dynamically set the form action using jQuery.
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)

832 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