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

Ajax problem, wont work in IE

The following code works fine in Firefox/Netscape but wont work in IE.
I suspect the problem is with one of these two simple functions. If
there is no obvious error Ill paste the entire code.

///////////////////////////////////////////////////////

function get_last_updated() {

http.open( 'get', url );
http.onreadystatechange = handleHttpResponse;
http.send(null);

setTimeout( 'get_last_updated()', 5000 );

} // end function

///////////////////////////////

function handleHttpResponse() {

if (http.readyState == 4) {

last_updated = http.responseText;

if ( ! first_updated ) { first_updated = last_updated; }

if ( last_updated - first_updated > 0 )
{ window.location = url; }
}
} // end function

///////////////////////////////////////////////////////

Feb 2 '06 #1
14 3049
sq****@peoriadesignweb.com wrote:
The following code works fine in Firefox/Netscape but wont work in IE.
I suspect the problem is with one of these two simple functions. If
there is no obvious error Ill paste the entire code.

///////////////////////////////////////////////////////

function get_last_updated() {

http.open( 'get', url );
http.onreadystatechange = handleHttpResponse;
http.send(null);


As a guess, the problem is with wherever you've defined the http object.
It should look something like the stuff here:

<URL:http://jibbering.com/2002/4/httprequest.2004.html>
The relevant part is copied below where it the equivalent object is
called xmlhttp.
Creating the object

In Internet Explorer, you create the object using new
ActiveXObject("Msxml2.XMLHTTP") or new
ActiveXObject("Microsoft.XMLHTTP") depending on the version of MSXML
installed. In Mozilla and Safari (and likely in future UA's that
support it) you use new XMLHttpRequest()

This means that you need to show different script to different
browsers, as what works in one, will error in another. The script
below does this, and if it's not supported, the variable is set to
false to allow for appropriate error messages and recovery with
degrading to more normal HTTP transaction methods when the object
isn't available. This degradation is important, even in IE the objects
can often be blocked by slightly raised security settings (popular due
to the commonly exploited holes of course). Where possible degrade,
some approaches are talked about below, if you really can't, I'd
recommend providing an alternative page aswell. GMail for example has
said they'll be providing a less demanding version in the future,
hopefully with no javascript at all, full degradation.
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope
// with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}


--
Rob
Feb 2 '06 #2
Thanks, I tried that code but still not working in IE. I think it may
be because I am running an older version of IE6.0 ? I will do a windows
update to see if that fixes it?

Feb 2 '06 #3
sq****@peoriadesignweb.com said the following on 2/2/2006 12:50 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
Thanks, I tried that code but still not working in IE.
Post a URL to a sample page that you have made that doesn't work in IE.

I think it may be because I am running an older version of IE6.0 ?
Doubtful but possible.
I will do a windows update to see if that fixes it?


You should update your windows and browser to make sure they are fully
patched but it shouldn't have anything to do with this.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Feb 2 '06 #4
sq****@peoriadesignweb.com wrote:
Thanks, I tried that code but still not working in IE. I think it may
be because I am running an older version of IE6.0 ? I will do a windows
update to see if that fixes it?


You should already have a fully patched Windows system, but I doubt that
it will make any difference. XMLHttpRequest was introduced with IE 5.0.

IE 6.0 is the latest version, the full vision number I have is
6.0.2800.1106.xpsp2.050301-1526. IE 7 beta is around but kinda
irrelevant here.

Maybe it is security related... post a URL.
--
Rob
Feb 2 '06 #5

Randy Webb wrote:
Post a URL to a sample page that you have made that doesn't work in IE.


Here's a test page I have set up:

http://web.peoriadesignweb.com/dev/ajax/

http://web.peoriadesignweb.com/cgi-b...imple/demo.cgi

If you go to second page and make a reservation, then the first page
should update with a message saying 'Page has been updated':

Feb 2 '06 #6
sq****@peoriadesignweb.com wrote:
Randy Webb wrote:
Post a URL to a sample page that you have made that doesn't work in IE.

Here's a test page I have set up:

http://web.peoriadesignweb.com/dev/ajax/

http://web.peoriadesignweb.com/cgi-b...imple/demo.cgi

If you go to second page and make a reservation, then the first page
should update with a message saying 'Page has been updated':


It doesn't work at all. You added the code to initialise the xmlhttp
object, but kept references to http in your original code. Change one
or the other.
--
Rob
Feb 2 '06 #7

RobG wrote:
It doesn't work at all. You added the code to initialise the xmlhttp
object, but kept references to http in your original code. Change one
or the other.


At the top of the script I have a line:

var http = getHTTPObject(); // We create the HTTP Object

so getHTTPObject basically returns the xmlhttp object created inside
it.

I just did the windows update and it is still not working. Could it be
some other security setting inside IE 6, I am using: 6.0.2800.1106

Feb 2 '06 #8
sq****@peoriadesignweb.com wrote:
Thanks, I tried that code but still not working in IE. I think it may
be because I am running an older version of IE6.0 ? I will do a windows
update to see if that fixes it?

Stick in a few alerts to make sure your http object is valid.

--
Ian Collins.
Feb 2 '06 #9
sq****@peoriadesignweb.com wrote:
RobG wrote:
It doesn't work at all. You added the code to initialise the xmlhttp
object, but kept references to http in your original code. Change one
or the other.

At the top of the script I have a line:

var http = getHTTPObject(); // We create the HTTP Object

so getHTTPObject basically returns the xmlhttp object created inside
it.

I just did the windows update and it is still not working. Could it be
some other security setting inside IE 6, I am using: 6.0.2800.1106

I get an error from get_last_updated() just before http.send(). You have:

http.open( 'get', url );
http.onreadystatechange = handleHttpResponse;
http.send(null);
Try:

http.open("GET", url);
http.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
handleHttpResponse();
}
}
xmlhttp.send(null);
--
Rob
Feb 2 '06 #10

sq****@peoriadesignweb.com wrote:
At the top of the script I have a line:

var http = getHTTPObject(); // We create the HTTP Object

so getHTTPObject basically returns the xmlhttp object created inside
it.


I would say the main reason why it's not working on Internet Explorer
is that you simply are not creating the xmlhttp object correctly for
IE. In your getHTTPObject function you are doing the following:

try
{
http = new XMLHttpRequest();
}
catch (e)
{
http = false;
}

You are using a method that would obviously would only work on non-IE
browsers. At least until IE7 shows up. Try using the following method
instead to create the XMLHttpRequest object:

if(window.XMLHttpRequest)
{
//for IE7, Mozilla, Safari, etc: use native object
var xmlHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
//use ActiveX control for IE5.x and IE6
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

Feb 2 '06 #11
sq****@peoriadesignweb.com said the following on 2/2/2006 1:20 AM:
Randy Webb wrote:
Post a URL to a sample page that you have made that doesn't work in IE.


Here's a test page I have set up:

http://web.peoriadesignweb.com/dev/ajax/

http://web.peoriadesignweb.com/cgi-b...imple/demo.cgi

If you go to second page and make a reservation, then the first page
should update with a message saying 'Page has been updated':


The problem is not with the XMLHTTPRequest, it is a problem with your
cgi not returning what you think it is or what it should.

Find this section of your code:

if ( ! first_updated ) { first_updated = last_updated; }
if ( last_updated - first_updated > 0 )

Change it to look like this:
if ( ! first_updated ) { first_updated = last_updated; }
document.getElementById('myDiv').innerHTML +=
'First Updated = ' + first_updated +
' and last_updated = ' + last_updated + '<br>';
if ( last_updated - first_updated > 0 )

And then in your body add this HTML:

<div id="myDiv"></div>

Then test it. Then, go make a reservation, and watch your test page.
It doesn't return a modified value. I even added a new Date().getTime()
parameter to the URL to stop it from trying to get it from the cache and
it still doesn't update properly.

Have a look at your cgi script to make sure it is doing what it is
supposed to be doing.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 2 '06 #12
web.dev said the following on 2/2/2006 2:10 AM:
sq****@peoriadesignweb.com wrote:
At the top of the script I have a line:

var http = getHTTPObject(); // We create the HTTP Object

so getHTTPObject basically returns the xmlhttp object created inside
it.


I would say the main reason why it's not working on Internet Explorer
is that you simply are not creating the xmlhttp object correctly for
IE.


It is properly being created. The problem is the return value from the
cgi script, not in the HTTPRequest Object.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 2 '06 #13
Randy Webb wrote:
It is properly being created. The problem is the return value from the
cgi script, not in the HTTPRequest Object.


I have just added the code you suggested, however firefox is showing
the
correct result, but IE does not. Could it have to do with cacheing?

Feb 2 '06 #14
I have resolved the issue by changing it from GET to POST. Apparently
it was some caching problem in IE if I use GET.

Feb 2 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gaffar | last post by:
Hello. My name is Gaffar. I am handling an module in a Project. This application interface is slow and inefficient. So Client told "implement an AJAX Solution which will increase speed and...
9
by: darrel | last post by:
Last week I asked about ASP.net 2.0 AJAX frameworks and there appears to be several to choose from. I haven't used ASP.net 2.0 yet, but from doing a bit of reading, it appears that ASP.net 2.0...
7
by: Ivan Marsh | last post by:
Hey Folks, I'm having a heck of a time wrapping mind around AJAX. Anyone know of a simple, straight-forward example for pulling a simple query from mysql with PHP using AJAX? As I...
1
exoskeleton
by: exoskeleton | last post by:
Hi..to all expert...i have this situation .. i cant get the value of the file field in the other page..im using a simple javascript like this... example: // this is page1.php <head> ...
4
by: Bruno Alexandre | last post by:
Hi guys, I have this page that needs to be populated with 2 diferent web services, and each one takes more or less 10 seconds to finish populate his own part, so I move on to the multi threading...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
0
by: kal | last post by:
I have a gridview on my page - the 'onSelIndexChan' of which is wired to a ajax update panel - via triggers. this works fine but the grids paging wont work - or rather it fires a post back but...
3
by: dreamznatcher | last post by:
Hello, I found a script here: http://www.webtoolkit.info/ajax-file-upload.html which supposedly allows you to upload files using AJAX (I'm not an expert). The site claims it's the best way to...
16
by: ziycon | last post by:
I have this below code that calls an ajax page my problem is how do i pass the form values into the ajax page? I've tried $_REQUEST but it wont pick them up?? <form method="post"...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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,...

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.