Loading...
Copy code
Close
Permalink
Close
Please tell us why you want to mark the subject as inappropriate.
(Maximum 200 characters)
Report Inappropriate
Cancel
Private Message
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Cancel
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Update
Cancel
Feedback
Email ID
Subject :
Comments :
Send
Cancel
Private Message
Type the characters you see in the picture below.
Type the characters you see in the picture below.
Attach files
Desktop
Google Docs
Each Attachment size should not exceed 1.0 MB.
Max no of attachments : 3
Loading User Profile...
guest
Response title
This is preview!
Attachments
Publish
Back to edit
Cancel
(
)
Sign In
New to this Portal? Click here to
Sign up
You can also use the below options to login
Login with Facebook
Login with Google
Login with Yahoo
jQuery
Plugins
UI
Meetups
Forum
Blog
About
Donate
All Forums
Recent Posts
Log In
Search
jQuery
Search
jQuery Forum
Screen name:
pdeluca
pdeluca's Profile
1
Posts
2
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Ideas
Problems
Expanded view
List view
Private Message
Sorting XML created by ajax call
[3Replies]
03-Mar-2014 04:04 PM
Forum:
Using jQuery
I have an ajax call that pulls data from a MS SQL databse using an API. I'm trying to sort based on the CNT_SEQ_ID element of the XML, then create a list of three items to put inside a div in the HTML. I have code that does everything but the sort :
$.ajax({
type: "POST",
async: false,
data: strParams,
url: "/AJAXUtilities.aspx",
success: function(msg){
msg = $.createXMLDocument(msg);
//$("#newscatlist").html(msg); //show results
var li_count = 0;
$(msg).find('CONTENT_SEARCH').each(function(){
if ($(this).find("CNT_AVAILABLE").text() == "T") {
var objid = $(this).find("CNT_CONTENT_ID").text();
var title = $(this).find("CNT_TITLE").text();
if (title.length >= 40){
var trimtitle = title.substring(0,39);
list = list.concat("<li><a href=\"/MyOptions.aspx?id=" + objid + "\">" + trimtitle +"...</a></li><hr>");
}else{
list = list.concat("<li><a href=\"/MyOptions.aspx?id=" + objid + "\">" + title +"</a></li><hr>");
}
li_count = li_count+1;
if (li_count == 3) {
return false;
}
}
});
}
});
list = list.concat("</ul>");
list = list.concat("<br /><a href=\"\">View previous clinical updates>></a>");
$("#newscatlist").append(list);
return list;
Here's my modified code attempting to do the sort:
$.ajax({
type: "POST",
async: false,
data: strParams,
url: "/AJAXUtilities.aspx",
success: function(msg){
msg = $.createXMLDocument(msg);
var li_count = 0;
var results = [];
$(msg).find('CONTENT_SEARCH').each(function(){
if ($(this).find("CNT_AVAILABLE").text() == "T") {
var seqtext = $(this).find("CNT_SEQ_ID").text();
results.push({
seq: seqtext,
objid: $(this).find("CNT_CONTENT_ID").text(),
title: $(this).find("CNT_TITLE").text()
});
results.sort(function (a, b) {return a.seqtext > b.seqtext;});
var html = [];
html.unshift("<ul style=\"list-style: none; text-indent: -1.2em;\" class=\"newsupdates-list\" id=\"newsupdates-" + strCategoryID + "\">");
newscatlist.innerHTML=html;
if (title.length >= 40){
var trimtitle = title.substring(0,39);
html.push("<li><a href=\"/MyOptions.aspx?id=" + this.objid + "\">" + this.trimtitle +"...</a></li><hr>");
}else{
html.push("<li><a href=\"/MyOptions.aspx?id=" + this.objid + "\">" + this.title +"</a></li><hr>");
}
li_count = li_count+1;
if (li_count == 3) {
return false;
}
}
});
html.push("<br /><a href=\"\">View previous clinical updates>></a>");
$("#newscatlist").append(html.join(''));
}
});
What am I doing wrong?
«Prev
Next »
Moderate user : pdeluca
Forum