Solved

AJAX responseText Each Value Append UL?

Posted on 2014-09-29
3
189 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 55

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 55

Expert Comment

by:Julian Hansen
ID: 40353186
You are welcome - thanks for the points.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

829 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