Solved

json append to second select

Posted on 2014-03-28
2
276 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:Seven price
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Seven price
ID: 39962291
listItems.messages was the key thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
The viewer will learn how to dynamically set the form action using jQuery.
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…

636 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