1

I'm trying to work with two XML files. I use the second highlighted answer in this thread [1] as a base script.

This is what I got:

jQuery.extend({
getValues: function(url) {
var result = null;
$.ajax({
    url: url,
    type: 'get',
    dataType: 'xml',
    async: false,
    success: function(data) {
        result = data;
    }
});
return result;
}
});


var party1 = $.getValues('http://data.riksdagen.se/voteringlista/?rm=2010%2F11&bet=&punkt=parti=M&valkrets=&rost=&iid=&sz=500&utformat=xml&gruppering=bet')
var party2 = $.getValues('http://data.riksdagen.se/voteringlista/?rm=2010%2F11&bet=&punkt=&parti=S&valkrets=&rost=&iid=&sz=500&utformat=xml&gruppering=bet')

$(party1).find('votering').each(function(){
var id = $(this).find("forslagspunkt").text()
partyTwo(id)
//-------------------------------------
//HERE I RUN A FEW SIMPLE IF STATEMENTS
//------------------------------------

})

function partyTwo(id) {
$(party2).find('votering').filter(function() {
    return $(this).find("forslagspunkt").text() == id;
    }).each(function () {

//-------------------------------------
// AGAIN, A FEW SIMPLE IF STATEMENTS
//------------------------------------      

            return vote 
})  
}

This leaves me with two problems:
1) partyTwo(id) returns 'undefined', but works fine if I manually insert an id outside.
2) The whole script runs very slow (+5 sec to load).

Any thoughts?

[1] JQuery - Storing ajax response into global variable

Community
  • 1
  • 1
Jens
  • 121
  • 1
  • 9
  • 1
    Does `partyTwo()` actually return anything? Does the script run slow, or is it the loading that is slow? – Paul Grime Sep 20 '11 at 21:14
  • `partyTwo()` returns the correct value if I manually insert an id. For example: `partyTwo("23")`. And it is the loading that takes a lot of time. – Jens Sep 27 '11 at 16:01

0 Answers0