Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   [Help Needed] Javascript Team Finder (http://www.chiefdelphi.com/forums/showthread.php?t=142849)

Mr_Moko 30-01-2016 13:48

[Help Needed] Javascript Team Finder
 
Greetings Chief Delphi members!
I'm from from FRC 2729 Storm Robotics and I was wondering if someone could help with an issue that we're having with our Team Number Finder in JavaScript.
We can get one page of team numbers (500 numbers) off of any given page using The Blue Alliance api due to the fact that the HTTP request only executes on the last iteration of the for loop. The problem we are having is that when we try to get more than one page, the values become undefined.
If someone could look through the code and lend us a hand, that would be wonderful!

HTML
JavaScript

Thanks in advance for any help that is given!

jlmcmchl 30-01-2016 13:53

Re: [Help Needed] Javascript Team Finder
 
Could you post a pastebin link, instead of quoting the code? It's really hard to read when you lose all the formatting.

Mr_Moko 30-01-2016 14:01

Re: [Help Needed] Javascript Team Finder
 
Quote:

Originally Posted by jlmcmchl (Post 1532470)
Could you post a pastebin link, instead of quoting the code? It's really hard to read when you lose all the formatting.

Replaced the Quotes with Hyperlinks to Pastebin.
Thanks for the advice! I'm not quite sure why I didn't think of that to begin with.

hardcopi 30-01-2016 14:01

Re: [Help Needed] Javascript Team Finder
 
PHP Code:

document.getElementById("blank").innerHTML out


You appear to be overwriting the html of your div every iteration. Not sure in core javascript but in jquery it would be
PHP Code:

$('#blank').append(out); 

A jsfiddle or pastbin would have been easier to debug though. :)

Mr_Moko 30-01-2016 14:08

Re: [Help Needed] Javascript Team Finder
 
Quote:

Originally Posted by hardcopi (Post 1532477)
PHP Code:

document.getElementById("blank").innerHTML out


You appear to be overwriting the html of your div every iteration. Not sure in core javascript but in jquery it would be
PHP Code:

$('#blank').append(out); 

A jsfiddle or pastbin would have been easier to debug though. :)

You posted just before I updated the post to have inks to Pastebin instead of quotes, thank your for opinion, I'll see if that helps!

Andrew Lobos 30-01-2016 14:34

Re: [Help Needed] Javascript Team Finder
 
I think this JS will output what you expect (or something close): https://gist.github.com/4ndr3w/b924b0762416c0ba6885

In Chrome I get a big comma separated list of teams from 1 to something in the 6000's Note that the output has no guarantee of order since the HTTP requests are returning asynchronously.

hardcopi is right that it's probably better to append to the div. Your implementation will work since you are appending output to a global string and then writing the whole string back out to the div every loop, but it's not as clean

Mr_Moko 30-01-2016 15:03

Re: [Help Needed] Javascript Team Finder
 
Quote:

Originally Posted by Andrew Lobos (Post 1532504)
I think this JS will output what you expect (or something close): https://gist.github.com/4ndr3w/b924b0762416c0ba6885

In Chrome I get a big comma separated list of teams from 1 to something in the 6000's Note that the output has no guarantee of order since the HTTP requests are returning asynchronously.

hardcopi is right that it's probably better to append to the div. Your implementation will work since you are appending output to a global string and then writing the whole string back out to the div every loop, but it's not as clean

Thank you so much for your fix! If we use your version then I'll make sure to credit you for the fix.
I also agree with hardcopi and I'll possibly see what I can do about doing that, but for now, thanks again for now I believe we'll use your version.
Again, thank you!


All times are GMT -5. The time now is 00:43.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi