473,836 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

155 New Member
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();
  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. }
  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;
  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;
  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. }
Oct 6 '09 #1
9 2071
16,027 Recognized Expert Moderator MVP
What exactly is the code supposed to be doing? Why do you have 5 or so Ajax calls?
Oct 6 '09 #2
155 New Member
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 :)
Oct 6 '09 #3
155 New Member
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.....

Oct 7 '09 #4
8,658 Recognized Expert Moderator Expert
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
155 New Member
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
8,658 Recognized Expert Moderator Expert
does look troublesome. you’ll probably get into an infinite loop.

further is if (element.innerH TML = res) intended? (if (res) seems better)
Oct 7 '09 #7
155 New Member
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();
  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
8,658 Recognized Expert Moderator Expert
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.

Expand|Select|Wrap|Line Numbers
  1. setTimeout(MakeRequest2, 4000);
Oct 7 '09 #9
155 New Member
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

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 comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
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 difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
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. Unfortunately these ad hominem rhetorts are frequently introduced into purely technical discussions on the feasibility of supporting such functionality in C++. That usually serves to divert the discussion from the technical subject to a discussion of the...
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 working (actually playing) on porting Alien vs Predator to Linux. I am using the code that is available via CVS from icculus.org. I recently upgraded my gcc to 3.4.1 and now a portion of the code doesn't compile. Nothing in the code has changed.
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 'search' may be clicked on by the user and the user can then search all records by postcode. I want to do this to prevent duplicate data entry.
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 a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
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) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
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 personal server. Are there any code samples or books that someone can recommend so that I can implement this. I would prefer VB.NET code, but I am willing to convert from C# if necessary.
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 solution. My code can be downloaded from here: http://www.tprimke.net/konto/PyObject-problem.tar.bz2. There are some scripts for GNU/Linux system (bash to be precise). All you need to know is that there are four classes. (Of course, you may...
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 set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.