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

  • SEARCH
  • Home
  • 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 5963375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:14:33+00:00 2026-05-22T19:14:33+00:00

I have a jquery script that searches a php file that produces an XML

  • 0

I have a jquery script that searches a php file that produces an XML file. The XML file example is here

            <sites>
            <name>Ascot Racecourse</name>
            <address1>Berkshire</address1>
            <postcode>SL5 7JX</postcode>
            <name>Aston Villa Football Club</name>
            <address1>Villa Park</address1>
            <postcode>B6 6HE</postcode>
            <name>Asda 1 Year Celebration</name>
            <address1>Park In Ipswich</address1>
            <postcode>IP</postcode>
            <name>ASDA FULWOOD</name>
            <address1>ASDA FULWOOD</address1>
            <postcode>ASDA</postcode>
            <name>ASDA TEST 5</name>
            <address1>ASDA TEST 5</address1>
            <postcode>ASDA TES</postcode>
            <name>ASDA 50</name>
            <address1>ASDA 50</address1>
            <postcode>ASDA 50</postcode>
            </sites>

My JQ script works fine and gets all the data using the following

          $(document).ready(function(){ 
          $.ajax({
          type: "GET", 
          url: "search_action.php" + string ,
          dataType: "xml",
          success: disxml                                                  });
            })

       } // function 

      function disxml(data){

      $(data).find('sites').each(function(row) {  
                  var name    = $(this).find('name').text(); 
                  var add1    = $(this).find('address1').text(); 

                  display +=   "<b>" + name + "</b> - " + add1  + "<br>"   ;


                  })

      divbox.html(display) ; // draw contents 
      } 

I am happy from checking the XML file in a browser that the result is fine BUT the problem is the value of the variable ‘display’ I am expecting an ordered list with a line break after each name and address in the xml file, but what I get is ALL the names followed by ALL the addresses. I believe the script is working through a loop and should do what I want but it just doesn’t

if it helps this is the value of ‘display’

Ascot RacecourseAston Villa Football ClubAsda 1 Year CelebrationASDA FULWOODASDA TEST 5ASDA 50-BerkshireVilla ParkPark In IpswichASDA FULWOODASDA TEST 5ASDA 50

Can anyone tell me what I am doing wrong please ?

Thanks in advance

Mick

  • 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-05-22T19:14:34+00:00Added an answer on May 22, 2026 at 7:14 pm

    This is becasue you are doing the following:

    $(data).find('sites').each(function(row) {  
       var name    = $(this).find('name').text(); 
       var add1    = $(this).find('address1').text(); 
    
       display +=   "<b>" + name + "</b> - " + add1  + "<br>"   ;
    })
    

    You are cycling through each sites node, which there is one of, and getting ALL the name nodes within it, and then getting the text of ALL those nodes. For it to work like you are expecting you will have to modify your XML like:

    <sites>
       <site>
          <name>Ascot Racecourse</name>
                <address1>Berkshire</address1>
                <postcode>SL5 7JX</postcode>
       </site>
       <site>
          <name>Aston Villa Football Club</name>
                <address1>Villa Park</address1>
                <postcode>B6 6HE</postcode>
       </site>
       <!-- etc... -->
    </sites>
    

    And do the following:

    $(data).find('sites').find('site').each(function(row) {  
       var name    = $(this).find('name').text(); 
       var add1    = $(this).find('address1').text(); 
    
       display +=   "<b>" + name + "</b> - " + add1  + "<br>"   ;
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jQuery code. I have called an Ajax function file, file.php, that
i have this jquery script that clicks on link add info then hides it
I have a jQuery script that runs a function every second with setinterval. But
I have a jquery-script that triggers on mouseover on a div like this: <div
I have a jQuery script that works perfectly fine in Chrome 11 and Firefox
i have a client side jquery script that logs the user off after 5
How have you guys handled working with jQuery includes <script type=text/javascript src=jquery.js></script> in Asp.Net
I'm struggling to find the right terminology here, but if you have jQuery object...
I have some jQuery/JavaScript code that I want to run only when there is
I have a jQuery datepicker that I want to restrict non work days -

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.