My first time on this forum. I hope someone can help me out.
I am trying to get 11 values from several different identically structured webpages. I have the list of webpages saved as a global array. I am trying to access the sites one at a time and acquire the data using a for loop saving each value into an array that was declared as a global variable. I am trying to access the site from Body of the html and place each value into a row of a table and then empty the array with the values and start the for loop over accessing the next site.
I tested to see that the page is being read properly and that the value array has the correct data in it. As far as I can tell that all works fine. However when trying to write it to my table it comes out as a table full of the word "undefined."
I hope this is all clear. I removed some of the specifics from the code for privacy reasons. Any advice is appreciated.
Thanks
Expand|Select|Wrap|Line Numbers
- <html>
- <title>HTML searching</title><head>
- <script type="text/javascript" language="javascript">
- var sites = new Array("http://site1.com",http://site2.com","http://site3.com","http://site4.com");
- var value = new Array();
- var http_request = false;
- function makeRequest(url, parameters) {
- try {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
- } catch (e) {
- alert("Permission UniversalBrowserRead denied.");
- }
- http_request = false;
- http_request = new XMLHttpRequest();
- if (http_request.overrideMimeType) {
- http_request.overrideMimeType('text/xml');
- }
- if (!http_request) {
- alert('Cannot create XMLHTTP instance');
- return false;
- }
- http_request.onreadystatechange = alertContents;
- http_request.open('GET', url + parameters, true);
- http_request.send(null);
- }
- function alertContents() {
- if (http_request.readyState == 4) {
- if (http_request.status == 200) {
- var the_page = http_request.responseText;
- //... do some things to parse through the html
- for(var i=0; i<11; i++)
- {
- //parse through data to save 11 values
- value[value.length]=parsedString;
- }
- //alert("TESTING " + value);
- } else {
- alert('There was a problem with the request.');
- }
- }
- }
- </script>
- </head>
- <body>
- <table border=1>
- <tr>
- <script>
- for(var i=0; i<4; i++)
- {
- makeRequest(sites[i], '');
- for(var j=0; j<11; j++)
- {
- document.write('<td>'+value[j]+'</td>');
- }
- document.write('</tr><tr>');
- }
- value.length=0;
- </script>
- </body>
- </html>