473,394 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

trouble with XMLHttpRequest

Plater
7,872 Expert 4TB
I have a simple page that performs a simple request on a 5second interval. It requests some data from a script I have, and then parses and updates the page accordingly. Simple.
I am pretty sure my problem is I am using some kind of IE-specific calls because it's not working in firefox. Firefox shows no errors, but it doesn't do anything.
I am thinking it does like the way I did the interval thing. Is setInterval not a valid javascript call?
It functions correctly in IE and has no errors in firefox, so I am suspicious of that interval call.

I have the code here:
Expand|Select|Wrap|Line Numbers
  1. function createRequestObject() 
  2. {//creates an httprequest object
  3.     var ro;
  4.  
  5.     var browser = navigator.appName;
  6.     if(browser == "Microsoft Internet Explorer"){
  7.         ro = new ActiveXObject("Microsoft.XMLHTTP");
  8.     }else{
  9.         ro = new XMLHttpRequest();
  10.     }
  11.     return ro;
  12. }
  13.  
  14. function returnObjById( id ) 
  15.     if (document.getElementById) 
  16.         var returnVar = document.getElementById(id); 
  17.     else if (document.all) 
  18.         var returnVar = document.all[id]; 
  19.     else if (document.layers) 
  20.         var returnVar = document.layers[id]; 
  21.     return returnVar; 
  22.  
  23. var http = createRequestObject();
  24. var scriptlocation="/refresh.cgi";
  25. var ourinterval=setInterval("SendUpdate()",5000);    
  26.  
  27. function SendUpdate()
  28. {
  29.     var action="DATETIME&TEMPERATURE&HUMIDITY&SAMPLESTATE";
  30.     action+="&CHAN1&CHAN2&CHAN3&CHAN4&CHAN5&CHAN6&CHAN7&CHAN8&CHAN9&CHAN10";
  31.     http.open('get', '/refresh.cgi?'+action+'&time='+ new Date().getTime());
  32.   http.onreadystatechange = handleSendUpdateReponse;
  33.   http.send(null);
  34. }
  35.  
  36. function handleSendUpdateReponse()
  37. {
  38.     if(http.readyState == 4)
  39.     {
  40.         var response = http.responseText;
  41.  
  42.         var update = new Array();
  43.         if ((response!="")&&(http.status=="200"))
  44.         {
  45.             if(response.indexOf('|' != -1)) 
  46.             {
  47.                 update=response.split('|');
  48.                 if (update.length>0)
  49.                 {
  50.                     if (update[1].indexOf("SUCCESS")>-1)
  51.                     {
  52.                         var line=update[1];
  53.  
  54.                         var things=new Array();
  55.                         things=line.split('&');
  56.                         var i;
  57.                         for (i=0;i<things.length;i++)
  58.                         {
  59.                             var nameval=things[i].split('=');
  60.                             if (i>0)
  61.                             {
  62.                                 returnObjById(nameval[0]).innerHTML=nameval[1];
  63.                             }
  64.                         }
  65.                     }
  66.                     else
  67.                     {
  68.                     }
  69.                 }
  70.             }
  71.             else
  72.             {
  73.             }
  74.         }
  75.         else
  76.           {
  77.               //clearInterval(ourinterval);
  78.           }
  79.     }
  80. }
  81.  
Jul 20 '07 #1
4 1228
gits
5,390 Expert Mod 4TB
hmmm ... tested it and it sets the interval correctly ... you may use the firebug-extension to trace this ... you get a lot of information about the request ... may be you don't get a response? because i'm quite sure the request is sent with your code ... (try a simple alert to test it's sent) ...

kind regards
Jul 20 '07 #2
Plater
7,872 Expert 4TB
Wow do I feel dumb now. I caught it on my own.
I had a little old school thought in there. I had the <!-- and --> tag surrounding the insides of my script like a good little mid-90s javascripter.

firefox took it literally and ignored all my javascript.


Although now I have new troubles
Jul 20 '07 #3
pbmods
5,821 Expert 4TB
Heya, Plater.

Glad to hear you got that part of it working.

What's it doing now?
Jul 21 '07 #4
Plater
7,872 Expert 4TB
It has been solved: http://www.thescripts.com/forum/thread680790.html
Heya, Plater.

Glad to hear you got that part of it working.

What's it doing now?
Jul 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mr_burns | last post by:
Hi there, I am using the following function to import a xml file whether the users browser be IE or Mozilla: function importXML(file) { var xmlDoc; var moz = (typeof document.implementation...
10
by: Matt Kruse | last post by:
I'm aware of the circular reference memory leak problem with IE/closures. I'm not sure exactly how to resolve it in this situation. Also, Firefox appears to grow its memory size with the same code....
3
by: brian.newman | last post by:
I'm having trouble with XML in IE. I wrote the following function and it works fine in Firefox, but when I try to run it in IE, I get the error "getElementsByTagName(..).0' is null or not an...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
4
by: agun | last post by:
Hello, Hi, i'm really a newbie in programming, especially javascript. I have one question in my mind right now. Sorry before if i'm not clear. Please see this example: ...
7
by: kaiser0427 | last post by:
Ok, I have cleaned up the code and fixed some errors in it. The problem I am having is with the timer. If you uncomment the alert it pauses after every record. when I replace it with setInterval...
2
by: gradinafrica | last post by:
I'm trying to create a log out button that uses AJAX to call a php file which ends the current session: //logout.php <?php if (!session_start()); session_destroy(); //Destroys the...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.