Ajax loading data from multiple xml files

J

jhoff

So, I'm in a pickle...

Lets say I have a page: http://www.gen2host.com/discgolf/index.html

and on this page, there are a list of links. These links will be
generated by 5 pieces of data pulled from each .xml file in a
subdirectory on the webserver.

Ex <A Href=" [DATA1] "> [DATA2] </a> [DATA3,4,5] as text.

Now, that being said, I have finished writing the javascript that
solves this problem by using a XMLHttpRequest on each file to be in
parsed. And If, at the end of each file being parsed, I spit my output
to the InnerHTML of a div, the page turns out looking ok...

( now heres the problem )

....except for the fact that all of the links seem to be in random
order. More specifically, they order themselves based on the time that
each xml file finished parsing.


In an attempt to sort all of the links before spitting them out on to
the div, I'm thinking of loading all of the data into a dynamic array
with each value consisting of an array of 5 values.

In the code posted above, I have successfully created the dynamic
array. My last attempt to get closer to fixing my sorted array problem
was to try using an onload statement, but it appears that when the page
is loaded, the XMLHttpRequests are still parsing, so It tells me the
array is null.

Any thoughts on how one might start a function once all of the
XMLHttpRequests have completed?

(sorry if none of that made any logical sense to anyone but me...)
 
M

Marc

jhoff said:
So, I'm in a pickle...

Lets say I have a page: http://www.gen2host.com/discgolf/index.html

and on this page, there are a list of links. These links will be
generated by 5 pieces of data pulled from each .xml file in a
subdirectory on the webserver.

Ex <A Href=" [DATA1] "> [DATA2] </a> [DATA3,4,5] as text.

Now, that being said, I have finished writing the javascript that
solves this problem by using a XMLHttpRequest on each file to be in
parsed. And If, at the end of each file being parsed, I spit my output
to the InnerHTML of a div, the page turns out looking ok...

( now heres the problem )

...except for the fact that all of the links seem to be in random
order. More specifically, they order themselves based on the time that
each xml file finished parsing.


In an attempt to sort all of the links before spitting them out on to
the div, I'm thinking of loading all of the data into a dynamic array
with each value consisting of an array of 5 values.

In the code posted above, I have successfully created the dynamic
array. My last attempt to get closer to fixing my sorted array problem
was to try using an onload statement, but it appears that when the page
is loaded, the XMLHttpRequests are still parsing, so It tells me the
array is null.

Any thoughts on how one might start a function once all of the
XMLHttpRequests have completed?

(sorry if none of that made any logical sense to anyone but me...)

it makes sence ;)

move all the bits that'll run on page load into a function init()
if (window.addEventListener) {
window.addEventListener('load', init, false);
} else if (window.attachEvent) {
window.attachEvent('onload', init);
} else {
alert('Get yourselve a normal browser!');
}
put a counter inside this block:

var i = 0;if (http_request.readyState == 4) {
if (http_request.status == 200) { i++;if counter = amount of xml
files to proces... run the function that sorts the array and then write it
to the div...
 
M

Marc

yay... let me try that again...

move all the bits that'll run on page load into a function init()

if (window.addEventListener) {
window.addEventListener('load', init, false);
} else if (window.attachEvent) {
window.attachEvent('onload', init);
} else {
alert('Get yourselve a normal browser!');
}


put a counter inside this block:

var i = 0;
if (http_request.readyState == 4) {
if (http_request.status == 200) {
i++;



if counter = amount of xml files to proces... run the function that sorts
the array and then write it
to the div...
 
J

jhoff

Thanks, that helped out a lot. It appears to be creating the array
completely before it kicks off the final populatedata() function...

Now to sort.... and test with lots more files.

Thanks again!
 
B

bobzimuta

I'm fascinated. Why are you loading these xml files to get golf course
data? I'm not knocking it; I'm interested in knowing the situation that
requires your solution.
 
R

Randy Webb

bobzimuta said the following on 7/10/2006 7:27 PM:
I'm fascinated.

I am fascinated by people who can't follow the general convention of a
Usenet group and read the FAQ of that group with regards to posting
style that is preferred in this group.
Why are you loading these xml files to get golf course data?

Maybe because the data s/he needs is in those xml files?
I'm not knocking it; I'm interested in knowing the situation that
requires your solution.

See above.
 
B

bobzimuta

Maybe some of us use Google Groups to do our usenet browsing. If you
don't like it, submit a bug report to Google. Otherwise, get used to it
and stop whining.

I didn't ask you why that person was using the XML format, so mind your
own business and stop trolling.
 
R

Randy Webb

bobzimuta said the following on 7/11/2006 4:47 PM:
Maybe some of us use Google Groups to do our usenet browsing.

Nothing wrong with that.
If you don't like it, submit a bug report to Google.

Submit a bug report to Google? What would it say?

Bug Report:

Your users are too ignorant to read and follow conventions. Please fix
this problem ASAP.

Yeah, nice bug report.
Otherwise, get used to it and stop whining.
I didn't ask you why that person was using the XML format, so mind your
own business and stop trolling.

This is Usenet. You post, it gets replied to and discussed. Get used to
it, it's the way it works.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Tue, 11 Jul 2006 13:47:48 remote, seen in
news:comp.lang.javascript said:
Maybe some of us use Google Groups to do our usenet browsing. If you
don't like it, submit a bug report to Google. Otherwise, get used to it
and stop whining.

There's no difficulty in doing it right when using Google Groups.

This is a Usenet newsgroup, to which Google have provided their own
peculiar form of Web interface. Experienced users of Usenet follow
long-established conventions.

If you find that, when you start a News reply, Google does not provide
the previous article in quoted form, note what Keith Thompson wrote in
comp.lang.c, message ID <[email protected]> :-
If you want to post a followup via groups.google.com, don't use
the "Reply" link at the bottom of the article. Click on "show
options" at the top of the article, then click on the "Reply" at
the bottom of the article headers.

Since that is what the experts in this newsgroup prefer to read, it will
be to your advantage to comply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top