Skip to content Skip to sidebar Skip to footer

Inserting Into Html5 Database With Jquery Loop

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

Solution 1:

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]);
     });
  });
}

Solution 2:

Post a Comment for "Inserting Into Html5 Database With Jquery Loop"