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 3234488
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:23:50+00:00 2026-05-17T17:23:50+00:00

Javascript is not my forte, so excuse me if this is incredibly obvious. I’m

  • 0

Javascript is not my forte, so excuse me if this is incredibly obvious.

I’m working on some code that creates a local database and table, retrieves an RSS feed, parses it, and adds information from each entry to the database.

$.ajax({
    type: "GET",
    url: feedurl,
    dataType: "xml",
    success: parseXml
});

function parseXml(xml){
    $(xml).find("item").each(function(){
        title = $(this).find("title").text();
        description = $(this).find("description").text();
        postype = $(this).find("postype").text();
        category = $(this).find("category").text();
        guid = $(this).find("guid").text();
        postid = $(this).find("postid").text();
        url = $(this).find("enclosure").attr('url');

        db.transaction(function(tx) {
        tx.executeSql('INSERT INTO Posts (title, description, postype, category, guid, postid) VALUES (?,?,?,?,?,?)', [title, description,postype,category,guid,postid]);
        });

        return true;
    });
}

Here’s the issue. Everything is working up to the insert query. The insert query is inserting data but it uses the same data (the last item in the RSS feed) every iteration. If I add alert() right before the ‘title’ variable or append the variables to a div, it all works without a problem. I don’t get it.

Help!

  • 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-17T17:23:50+00:00Added an answer on May 17, 2026 at 5:23 pm

    The transactions take a slight amount of time, and you’re sharing some global variables by missing the var keyword on your declarations. Adding var so iterations of the loop as it’s own variable set should fix the issue:

    function parseXml(xml){
      $(xml).find("item").each(function(){
         var $this = $(this),
             title = $this.find("title").text(),
             description = $this.find("description").text(),
             postype = $this.find("postype").text(),
             category = $this.find("category").text(),
             guid = $this.find("guid").text(),
             postid = $this.find("postid").text(),
             url = $this.find("enclosure").attr('url');
    
         db.transaction(function(tx) {
           tx.executeSql('INSERT INTO Posts (title, description, postype, category, guid, postid) VALUES (?,?,?,?,?,?)', [title, description,postype,category,guid,postid]);
         });
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some JavaScript and jQuery code that accepts only numeric input in
This is not a question specific about some javascript detail but I'm looking for
i need to execute some javascript functions from delphi code, but this functions fails
JavaScript is not my strong point, but then I'm not sure I'm hitting this
My javascript is not working right. It is simple pre-vailidation form and I can
I am having issues with javascript functionality not working in the admin area. When
I'm sure I'm contravening some deep dark law of javascript, but I'm not really
I am working on some javascript injection into m android webview. I am just
I have some graphs created with the Javascript library Protovis. Underneath this works by
Not sure if that is the right way to ask this or not but

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.