473,406 Members | 2,208 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,406 software developers and data experts.

i got my code working ,i want to know if i did it the right way :)

155 100+
i am not sure if this is the right way to use this AJAX script i did!

i want to know i f it will be compatible with IE 6 also!!

Expand|Select|Wrap|Line Numbers
  1. function getXMLHttp()
  2. {
  3. var xmlHttp;
  4.   try
  5.   {
  6.     //Firefox, Opera 8.0+, Safari
  7.     xmlHttp = new XMLHttpRequest();
  8.   }
  9.   catch(e)
  10.   {
  11.     //Internet Explorer
  12.     try
  13.     {
  14.       xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  15.     }
  16.     catch(e)
  17.     {
  18.       try
  19.       {
  20.         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  21.       }
  22.       catch(e)
  23.       {
  24.         alert("Your browser does not support AJAX!")
  25.         return false;
  26.       }
  27.     }
  28.   }
  29.   return xmlHttp;
  30. }
  31.  var xmlHttp;
  32. function MakeRequest2()
  33. {
  34.   var xmlHttp = getXMLHttp();
  35.  
  36.   xmlHttp.onreadystatechange = function()
  37.   {
  38.     if(xmlHttp.readyState == 4)
  39.     {
  40.       HandleResponse(xmlHttp.responseText);
  41.     }
  42.   }
  43. nocache = Math.random();
  44.   xmlHttp.open("GET", "check2.php?bid_id="+bid_id+'&nocache = '+nocache); 
  45.   xmlHttp.send(null);
  46.  setTimeout('MakeRequest2()', 4000);
  47. }
  48.  
  49. function HandleResponse(res)
  50. {
  51.   if (document.getElementById('id').innerHTML == res)
  52.     {}
  53.     else if (document.getElementById('id').innerHTML = res)
  54.     {
  55. MakeRequest();MakeRequest4();MakeRequest5();Audio();
  56.     }
  57.     else
  58.     {}
  59. }
  60. var xmlHttp1;
  61.  
  62. function MakeRequest()
  63. {
  64.   var xmlHttp1 = getXMLHttp();
  65.   xmlHttp1.onreadystatechange = function()
  66.   {
  67.     if(xmlHttp1.readyState == 4)
  68.     {
  69.       HandleResponset(xmlHttp1.responseText);
  70.     }
  71.   }
  72. nocache = Math.random();
  73.   xmlHttp1.open("GET", "check.php?bid_id="+bid_id+'&nocache = '+nocache); 
  74.   xmlHttp1.send(null);
  75. }
  76. function HandleResponset(response)
  77. {
  78.   if (document.getElementById('ResponseDiv').innerHTML == response)
  79.     { }
  80. else if (document.getElementById('ResponseDiv').innerHTML = response)
  81.     {
  82.   if (document.getElementById('ResponseDiv').innerHTML == "0")
  83.     {
  84.    nocache = Math.random();
  85. window.location.href = ("GET", "closed.php?bid_id="+bid_id+'&nocache = '+nocache);
  86.     }
  87.     else {}
  88. showPage(pageno);
  89.     }
  90.     else {}
  91. }
  92. var xmlHttp4;
  93.  
  94. function MakeRequest4()
  95. {
  96.   var xmlHttp4 = getXMLHttp();
  97.   xmlHttp4.onreadystatechange = function()
  98.   {
  99.     if(xmlHttp4.readyState == 4)
  100.     {
  101.       HandleResponse4(xmlHttp4.responseText);
  102.     }
  103.   }
  104. nocache = Math.random();
  105.   xmlHttp4.open("GET", "over4.php?bid_id="+bid_id+'&nocache='+nocache); 
  106.   xmlHttp4.send(null);
  107. }
  108. function HandleResponse4(over)
  109. {
  110.   if (document.getElementById('over').innerHTML == over)
  111.     {}
  112.     else if (document.getElementById('over').innerHTML = over)
  113.     {}
  114.     else
  115.     {}
  116. }
  117. var xmlHttp5;
  118. function MakeRequest5()
  119. {
  120.   var xmlHttp5 = getXMLHttp();
  121.   xmlHttp5.onreadystatechange = function()
  122.   {
  123.     if(xmlHttp5.readyState == 4)
  124.     {
  125.       HandleResponse5(xmlHttp5.responseText);
  126.     }
  127.   }
  128. nocache = Math.random();
  129.   xmlHttp5.open("GET", "over9.php?bid_id="+bid_id+'&nocache = '+nocache); 
  130.   xmlHttp5.send(null);
  131. }
  132. function HandleResponse5(over9)
  133. {
  134.   if (document.getElementById('over9').innerHTML == over9)
  135.     {}
  136.     else if (document.getElementById('over9').innerHTML = over9)
  137.     {}
  138.     else
  139.     {
  140.     }
  141. }
thanx!
Oct 6 '09 #1
9 2054
acoder
16,027 Expert Mod 8TB
What exactly is the code supposed to be doing? Why do you have 5 or so Ajax calls?
Oct 6 '09 #2
canabatz
155 100+
i got a table with results from the data base ,this table i s updating every 4
seconds ,the other calls are some limitations i put in the table ,there is two limitations ! ,this code i s working on my auction site ,there is one more call to check when to close the auction!

what i did there is to update the first call ,and if some thing as change, call the
other calls to check if everything is all right!

thats it :)

all the calls are working ,some times i got some call that is not working ,what im thinking is that the there is some problem with older browsers .

my question is if there is something wrong with my code! ,im not expert :)
thanx
Oct 6 '09 #3
canabatz
155 100+
can someone look at the code and tell me please if it's the right way?

do i need to make new getXMLhttp request to each call ,or there is a way to use one xmlhttp for all the call requests?

i used xmlhttp1 , xmlhttp2.....

thanx
Oct 7 '09 #4
Dormilich
8,658 Expert Mod 8TB
I think it shouldn’t be a problem to use only one request object, but how do you tell it, which response function to use?
Oct 7 '09 #5
canabatz
155 100+
the other response i did is to just fire the php file , the first request is checking
for changes in the database ,and if there is a change ,it is fireing the others

Expand|Select|Wrap|Line Numbers
  1. function HandleResponse(res)
  2. {
  3.   if (document.getElementById('id').innerHTML == res)
  4.     {}
  5.     else if (document.getElementById('id').innerHTML = res)
  6.     {
  7. MakeRequest();MakeRequest4();MakeRequest5();Audio();
  8.     }
  9.     else
  10.     {}
  11. }
is this the right way :) ?
Oct 7 '09 #6
Dormilich
8,658 Expert Mod 8TB
does look troublesome. you’ll probably get into an infinite loop.

further is if (element.innerHTML = res) intended? (if (res) seems better)
Oct 7 '09 #7
canabatz
155 100+
from what you see ,there is only one code that is looping every 4 seconds no?

Expand|Select|Wrap|Line Numbers
  1. function MakeRequest2()
  2. {
  3.   var xmlHttp = getXMLHttp();
  4.  
  5.   xmlHttp.onreadystatechange = function()
  6.   {
  7.     if(xmlHttp.readyState == 4)
  8.     {
  9.       HandleResponse(xmlHttp.responseText);
  10.     }
  11.   }
  12. nocache = Math.random();
  13.   xmlHttp.open("GET", "check2.php?bid_id="+bid_id+'&nocache = '+nocache); 
  14.   xmlHttp.send(null);
  15.  setTimeout('MakeRequest2()', 4000);
  16. }
this file check2.php is a small file 124 bytes ,and it's checking in the database for changes ,if there is a change ,then fireing the other requests!
Oct 7 '09 #8
Dormilich
8,658 Expert Mod 8TB
@canabatz
if you have only one XHR object and you call within the responsehandler this object again to make a new request, then you will trigger new requests each time the previous request completed.

PS
Expand|Select|Wrap|Line Numbers
  1. setTimeout(MakeRequest2, 4000);
Oct 7 '09 #9
canabatz
155 100+
so ,the way i have it ,it should be like that?
Oct 7 '09 #10

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

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
5
by: Kenton Groombridge | last post by:
Hi, I previous posted this in a gcc and g++ groups since that is the compiler I am working with, but I didn't get any response. Hopefully these are the right groups for this question. I am...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
19
by: Swaregirl | last post by:
Hello, I would like to build a website using ASP.NET. I would like website visitors to be able to download code that I would like to make available to them and that would be residing on my...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.