Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:58+00:00 2026-06-04T16:15:58+00:00

I have this URL format: http://localhost/find_retailers/index.html?modelCode=ABCD1234 I have an XML file consisting of: <products>

  • 0

I have this URL format:

http://localhost/find_retailers/index.html?modelCode=ABCD1234

I have an XML file consisting of:

<products>
<product modelcode="ABCD1234">
    <retailer id="1">
        <name>Retailer One</name>
        <logo>retailer_one.png</logo>
        <url>http://www.retailer-one.com/ABCD1234</url>
    </retailer>
</product>
<product modelcode="EFGH5678">
    <retailer id="2">
        <name>Retailer Two</name>
        <logo>retailer_two.png</logo>
        <url>http://www.retailer-two.com/EFGH5678</url>
    </retailer>
</product>

etc.

And I have the following jquery:

<script>
    $(document).ready(function(){
        $.ajax({
            type: "GET",
            url: "xml/retailers_param.xml",
            dataType: "xml",
            success: function(xml) {
                $(xml).find('product').each(function(){
                    function getUrlVars() {
                        var vars = {};
                        var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
                        vars[key] = value;
                        });
                    return vars;
                    }
                    var productUrl = getUrlVars()["modelCode"];
                    var modelcode = $(this).attr('modelcode');
                        if(modelcode == productUrl) {

                            $(this).find('retailer').each(function(){
                            var id = $(this).attr('id');    
                            var name = $(this).find('name').text();
                            var logo = $(this).find('logo').text();
                            var url = $(this).find('url').text();
                            $('<div class="retailer" id="retailer_'+id+'"></div>').html('<h3>'+name+'</h3><p><img src="img/logo/'+logo+'" alt="'+name+'" class="logo"/></p><div class="btnVisit"><a href="'+url+'" class="btnStyle" target="_blank"><span>Visit Store</span></a></div>').appendTo('#retailers');
                            });


                        }
                        else {
                            $('<div class="noRetailer"></div>').html('<h3>No Retailers for:</h3></br>'+productUrl+'').appendTo('#retailers');
                        }
                });
            }
        });
    });
 </script>

The problem is that it runs for every product node in the XML file. This means it displays the products but also the error message for every product node in the XML file.

I have tried including return(false); in the else statement but this does not work as it stops it progressing passed the first XML node.

Any ideas?

If I leave the else node empty or remove it then all is good but I really want to include a “No retailers for ‘modelcode'” type error for UX reasons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:15:59+00:00Added an answer on June 4, 2026 at 4:15 pm

    You should move the error test outside each, use a Boolean to test if a product was found or not.

            var foundProduct = false;
            $(xml).find('product').each(function(){
                function getUrlVars() {
                    var vars = {};
                    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
                    vars[key] = value;
                    });
                return vars;
                }
    
                var productUrl = getUrlVars()["modelCode"];
                var modelcode = $(this).attr('modelcode');
                    if(modelcode == productUrl) {
                        foundProduct = true;
                        $(this).find('retailer').each(function(){
                        var id = $(this).attr('id');    
                        var name = $(this).find('name').text();
                        var logo = $(this).find('logo').text();
                        var url = $(this).find('url').text();
                        $('<div class="retailer" id="retailer_'+id+'"></div>').html('<h3>'+name+'</h3><p><img src="img/logo/'+logo+'" alt="'+name+'" class="logo"/></p><div class="btnVisit"><a href="'+url+'" class="btnStyle" target="_blank"><span>Visit Store</span></a></div>').appendTo('#retailers');
                        });
    
    
                    }
            });
            if(!foundProduct) { /* Your error code here */ }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a URL in this format http://0.0.0.0:3000/#&ui-state=dialog . I want to check for
I have this model var Item = Backbone.Model.extend({ url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials' }); var onSuccess
I want to configure Kohana 2.x to have links in this format: http://localhost/mysite/web/admin/support instead
I have a problem with simple form for, I get this error url(http://localhost:3000/konkurrencer/new): Showing
i have a url in this format: http://www.example.com/manchester united note the space between manchester
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
How can I hide the parameters in Codeigniter? I have this URL: http://example.com/profile/1 I
I have a url string like this: http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g I need to send this url
I have this in my CSS file: body {style.css (line 3) background:#CDF8FF url(images/final_bg.jpg) no-repeat
I have a link in this format: http://user:pass@example.com How to get user and pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.