Jump to content

jQuery processing XML in reverse alpha-order


jcanker

Recommended Posts

I've set up a php page to process my customers by customer name and the business code which references the account (busname, buscode).  It's pulled from MySQL using ORDER BY busname ASC.

 

When I run the php on it's own, the xml is echoed properly and they all appear in alphabetical order. 

 

I'm using this jquery function to process the xml:

function getCustomerList() {
//this code modeled after tutorial at: http://think2loud.com/reading-xml-with-jquery/
  $.ajax({
    type: "POST",
    url: "php/selectcustomer.php",
    dataType: "xml",
    success: function(xml) {
		$(xml).find('Customer').each(function(){
			var buscode = $(this).find('buscode').text();//this refers to the current Customer
			var busname = $(this).find('busname').text();
			var selectlist = '</BR>'+buscode+'</br>'+busname+'</hr>';
			$('#rightColumn').prepend(selectlist);
		});
	}   	
  });
}

 

The function is called inside document.ready so it runs when the page loads.

 

This code adds the list to the top of #rightColumn as expected, but the list is ordered in reverse alpha-order.  The easy fix is just to reverse sort on the php side, but I'd like to understand why it's doing it so I understand jQuery better since I'm just learning it. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.