Solved

AJAX responseText Each Value Append UL?

Posted on 2014-09-29
3
170 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 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
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
Comment Utility
Excellent, it was late last night and couldn't get it, thanks...
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
You are welcome - thanks for the points.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 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

8 Experts available now in Live!

Get 1:1 Help Now