?
Solved

AJAX responseText Each Value Append UL?

Posted on 2014-09-29
3
Medium Priority
?
199 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
[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
3 Comments
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 2000 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 58

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 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