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.
- <script type="text/JavaScript">
-
- $(document).ready( function() {
- var timestamp = Math.round(new Date().getTime() / 1000);
-
- $("#<%=request.querystring("groupID")%>").html("><%= getGroup(request.querystring("groupID"),"qry","") %>").addClass("selectedMenuItem");
- loadXML(0,25);
-
- $("#sortOrder").change(function() {
- loadXML($("#sortOrder option:selected").val(),$("#limitBy option:selected").val());
- });
-
- $("#limitBy").change(function() {
- loadXML($("#sortOrder option:selected").val(),$("#limitBy option:selected").val());
- });
-
- $("input:checkbox").click(function() {
- loadXML($("#sortOrder option:selected").val(),$("#limitBy option:selected").val());
- });
- });
-
-
- function loadXML(so,lb) {
- timestamp = Math.round(new Date().getTime() / 1000);
- $("#wrapper").html('<div id="load"><img src="<%=rootWeb%>/images/loading.gif" alt="loading" align="center" /></div>');
- $("#results").empty();
- $.post("supportScripts/clothingXML.asp",{
- productGroup: "<%=request.querySTring("groupID")%>",
- productColour: "",
- productManu: "",
- sortOrder: so,
- limitBy: lb,
- ts: timestamp,
- colours:$("input:checkbox[name='colours[]']:checked").map(function() {
- return $(this).val();
- }).get(),
- manufacturer:$("input:checkbox[name='man[]']:checked").map(function() {
- return $(this).val();
- }).get()},
- function(xml) {
- convertXML(xml);
- $("#wrapper").empty();
- $('#results').html("Your Product was not found");
- },"xml")
- }
-
- function convertXML(xml) {
- var container = "";
- var counter = 1;
- var clothingRowStart = "\n\n<!-- Start Clothing Row-->\n\n<div class=\"clothingRow\">\n\n";
- var clothingRowEnd = "\n</div><!-- close clothing Row -->\n\n";
- var outputHTML = "";
- var status = parseInt($("status",xml).text());
- var records = parseInt($("records",xml).text());
-
- if (status==0) {
- alert("product not found");
- return false;
- } else {
- $("item",xml).each(function(id) {
- item = $("item",xml).get(id);
- var title = $("webtitle",item).text();
- var img = $("productImage",item).text();
- var price = $("price",item).text();
- var ref = $("stockCode",item).text();
- var links = $("link",item).text();
-
- 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\">£" +price+"</div></div>\n<!-- End Clothing Container " +ref+"-->\n\n";
- if (counter==1) {
- outputHTML += clothingRowStart;
- }
- outputHTML += container;
- if (counter==5) {
- outputHTML += clothingRowEnd;
- counter = 1;
- } else {
- counter++;
- }
- });
- }
- $('#results').ajaxComplete(function() {
- $("#wrapper").empty();
- $(this).html(outputHTML);
- $("#records").html("Showing " + records +" products").addClass("displayResultsRecords");
- });
- }
- </script>
regards
Graham