Small problem with AJAX results.

Small problem with AJAX results.

Hi

I have managed to develop a small application that returns results from a .asp script and using JQUERY I can display the results on the page.  I have also managed to extend the script so the resutls are then filtered down, so it is almost working the way I want it.  I have however now found a small glitch in that when a filter is applied that returns no results I get an alert box appear, and then the last set of successful results are displayed.

My thoughts are this is some kind of cache of the previously returned XML.  I have listed the code below for reference and thank anybody in advance for assistance in fixing this problem.

  1. <script type="text/JavaScript">
  2.  
  3. $(document).ready( function() {
  4.     var timestamp = Math.round(new Date().getTime() / 1000); 
  5.    
  6.     $("#<%=request.querystring("groupID")%>").html("><%= getGroup(request.querystring("groupID"),"qry","") %>").addClass("selectedMenuItem");
  7.     loadXML(0,25);
  8.    
  9.     $("#sortOrder").change(function() {
  10.         loadXML($("#sortOrder option:selected").val(),$("#limitBy option:selected").val());
  11.     });
  12.    
  13.     $("#limitBy").change(function() {
  14.         loadXML($("#sortOrder option:selected").val(),$("#limitBy option:selected").val());
  15.     });
  16.    
  17.     $("input:checkbox").click(function() {
  18.         loadXML($("#sortOrder option:selected").val(),$("#limitBy option:selected").val());
  19.     });
  20. });
  21.    
  22.    
  23. function loadXML(so,lb) {
  24.     timestamp = Math.round(new Date().getTime() / 1000);
  25.     $("#wrapper").html('<div id="load"><img src="<%=rootWeb%>/images/loading.gif" alt="loading" align="center"  /></div>');
  26.     $("#results").empty();
  27.     $.post("supportScripts/clothingXML.asp",{ 
  28.         productGroup: "<%=request.querySTring("groupID")%>", 
  29.         productColour: "", 
  30.         productManu: "",
  31.         sortOrder: so,
  32.         limitBy: lb,
  33.         ts: timestamp,
  34.         colours:$("input:checkbox[name='colours[]']:checked").map(function() {
  35.             return $(this).val();
  36.         }).get(),
  37.         manufacturer:$("input:checkbox[name='man[]']:checked").map(function() {
  38.             return $(this).val();
  39.         }).get()},
  40.         function(xml) {
  41.             convertXML(xml);
  42.             $("#wrapper").empty();
  43.             $('#results').html("Your Product was not found");
  44.         },"xml")
  45. }
  46.    
  47. function convertXML(xml) {
  48.     var container = "";
  49.     var counter = 1;
  50.     var clothingRowStart = "\n\n<!-- Start Clothing Row-->\n\n<div class=\"clothingRow\">\n\n";
  51.     var clothingRowEnd = "\n</div><!-- close clothing Row -->\n\n";
  52.     var outputHTML = "";
  53.     var status = parseInt($("status",xml).text());
  54.     var records = parseInt($("records",xml).text());
  55.    
  56.     if (status==0) {
  57.          alert("product not found");
  58.         return false;
  59.     } else {
  60.         $("item",xml).each(function(id) {
  61.             item = $("item",xml).get(id);
  62.             var title = $("webtitle",item).text();
  63.             var img = $("productImage",item).text();
  64.             var price = $("price",item).text();
  65.             var ref = $("stockCode",item).text();
  66.             var links = $("link",item).text();
  67.    
  68.             container = "<!-- start clothing container-->\n<div class=\"clothingItemContainer\"><div class=\"clothingItemImage\" style=\"background: url(" +img +") no-repeat center center; background-color:#FFFFFF;\"><a href=\""+links+"\"><img src=\"<%=rootWeb%>/images/spacer.gif\" alt=\"" +title+"\" title=\"" +title+"\" border=\"0\"/></a></div><div class=\"clothingItemTitle\"><a href=\""+links+"\">" +title+"</a></div><div class=\"clothingItemPrice\">&pound;" +price+"</div></div>\n<!-- End Clothing Container " +ref+"-->\n\n";
  69.             if (counter==1) {
  70.                 outputHTML += clothingRowStart;
  71.             }
  72.             outputHTML += container;
  73.             if (counter==5) {
  74.                 outputHTML += clothingRowEnd;
  75.                 counter = 1;
  76.             } else {
  77.                 counter++;
  78.             }
  79.         });
  80.     }
  81.     $('#results').ajaxComplete(function() {
  82.         $("#wrapper").empty();
  83.         $(this).html(outputHTML);
  84.         $("#records").html("Showing " + records +" products").addClass("displayResultsRecords");
  85.     });
  86. }
  87.  </script>
regards
Graham