tags:

views:

480

answers:

1

Hi, I'm using Ajax to get some XML, and then filling in some fields on a form with the results. There is a numerical field on the form and I would like to sort the results by this number (highest first).

How would I go about doing this in jQuery?

My js function code is currently:

function linkCounts() {
    ws_url = "http://archreport.epiphanydev2.co.uk/worker.php?query=linkcounts&domain="+$('#hidden_the_domain').val();
    $.ajax({
        type: "GET",
        url: ws_url,
        dataType: "xml",
        success: function(xmlIn){
            results = xmlIn.getElementsByTagName("URL");
            for ( var i = 0; i < results.length; i++ ) {
                $("#tb_domain_linkcount_url_"+(i+1)).val($(results[i].getElementsByTagName("Page")).text());
                $("#tb_domain_linkcount_num_"+(i+1)).val($(results[i].getElementsByTagName("Links")).text());
            }
            $('#img_linkcount_worked').attr("src","/images/worked.jpg");
        },
        error: function(){$('#img_linkcount_worked').attr("src","/images/failed.jpg");}
    });
}

The Links tag is the one I'm wanting to sort it on.

Thanks

For reference the XML that's getting returned is like the following:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Response>
  <ResponseCode>1</ResponseCode>
  <ResponseStatus>OK</ResponseStatus>
  <ReportId>2</ReportId>
  <UrlChecked />
  <MaxLinks>75</MaxLinks>
  <PagesFound>121</PagesFound>

  <URLs>
<URL>
      <Page>http://www.epiphanysolutions.co.uk/blog&lt;/Page&gt;
      <Links>78</Links>
    </URL>
    <URL>
      <Page>http://www.epiphanysolutions.co.uk/blog/&lt;/Page&gt;

      <Links>78</Links>
    </URL>
    <URL>
      <Page>http://www.epiphanysolutions.co.uk/blog/author/daniel-peden/&lt;/Page&gt;
      <Links>78</Links>
    </URL>
    <URL>

      <Page>http://www.epiphanysolutions.co.uk/blog/author/daniel-peden/page/2/&lt;/Page&gt;
      <Links>78</Links>
    </URL>
</URLS>
</Response>
A: 

Have you read this thread?

http://stackoverflow.com/questions/1134976/jquery-sort-list-items-alphabetically

:D

Cristian
Thanks for your response. I can't figure out how to use that to sort the URL tags based on the Links tag inside.
Probocop