Solved

AJAX responseText Each Value Append UL?

Posted on 2014-09-29
3
180 Views
Last Modified: 2014-09-30
Q. How do I return this ajax responseText into a ul li ?

Here's what I have so far, pretty close...

{"readyState":4,"responseText":"[\"value1\",\"value2\"]","responseJSON":["value1","value2"],"status":200,"statusText":"OK"}

 <ul id="list"></ul>

$.ajax ...
          ,complete: function (response) 
                             {
                                    var array = jQuery.parseJSON(response.responseText);

                                    alert(array); // Value1,Value2

                                    $.each(array.split(','), function(item)
                                    {
                                         $('#list').append('<li>' + item  + '</li>');
                                    });

Open in new window

0
Comment
Question by:WorknHardr
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 40351757
You are already converting the json string to an array - so you don't need to use split. Also your .each function use is incorrect - first param is index - second is value

var array = jQuery.parseJSON(response.responseText);

$.each(array, function (indx, item) {
	$('#list').append('<li>' + item + '</li>');
});

Open in new window

0
 

Author Closing Comment

by:WorknHardr
ID: 40353144
Excellent, it was late last night and couldn't get it, thanks...
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 40353186
You are welcome - thanks for the points.
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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

867 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

20 Experts available now in Live!

Get 1:1 Help Now