ajax problem

  • Thread starter Dennis van Weelden
  • Start date
D

Dennis van Weelden

Dear readers,

The purpose of the code which I have written is to show a special message
when you click on a paragraph. Unfortunately the code does give the
following error (in Firefox):
Fout: [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111
(NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://localhost/oe/oe_211.html :: anonymous :: line 10" data: no]
Bronbestand: http://localhost/oe/oe_211.html
Regel: 10
BTW: regel 10 is dutch for line 10 which is the line with if (request.status
== 200).

The strange thing is that the AJAX works well (i get the message), but in
Firefox and in Internet Explorer I get error codes.

I have the following code:
oe_211.html:
<html>
<head>
<title></title>
<script type="text/javascript">
function makeRequest()
{
var request=new XMLHttpRequest();
request.open("GET","oe_212.php");
request.onreadystatechange=function() {
if (request.status == 200)
{
if (request.readyState == 4)
{
var obj=document.getElementById("content");
obj.childNodes[0].data=request.responseText;
}
else
{
// nothing
}
}
else
{
// nothing
}
}
request.send(null);
}
</script>
</head>
<body>
<p id="trigger">Click here</p>
<p id="content">!!!</p>
<script type="text/javascript">
triggerObj=document.getElementById("trigger");
triggerObj.addEventListener("click",makeRequest,false);
</script>
</body>
</html>

and the following code:
oe_212.php:
<?php
echo "Hello world!";
?>

What can be the problem?

With kind regards,


Dennis
 
D

David Mark

Dear readers,

The purpose of the code which I have written is to show a special message
when you click on a paragraph. Unfortunately the code does give the
following error (in Firefox):
Fout: [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111
(NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::http://localhost/oe/oe_211.html:: anonymous :: line 10" data: no]
Bronbestand:http://localhost/oe/oe_211.html
Regel: 10
BTW: regel 10 is dutch for line 10 which is the line with if (request.status
== 200).

The strange thing is that the AJAX works well (i get the message), but in

Doesn't seem strange to me.
Firefox and in Internet Explorer I get error codes.

I have the following code:
oe_211.html:
<html>
<head>
<title></title>
<script type="text/javascript">
function makeRequest()
{
var request=new XMLHttpRequest();

You need to do some feature testing here. For one, this won't work in
IE6.
request.open("GET","oe_212.php");
request.onreadystatechange=function() {
if (request.status == 200)

This is backwards. You need to check for the appropriate readystate
before checking the status.
{
if (request.readyState == 4)
{
var obj=document.getElementById("content");
obj.childNodes[0].data=request.responseText;
}
else
{
// nothing
}
}
else
{
// nothing
}
}
request.send(null);}

</script>
</head>
<body>
<p id="trigger">Click here</p>
<p id="content">!!!</p>
<script type="text/javascript">
triggerObj=document.getElementById("trigger");
triggerObj.addEventListener("click",makeRequest,false);

IE uses attachEvent.
 
P

purcaholic

Dear readers,

The purpose of the code which I have written is to show a special message
when you click on a paragraph. Unfortunately the code does give the
following error (in Firefox):
Fout: [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111
(NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::http://localhost/oe/oe_211.html:: anonymous :: line 10" data: no]
Bronbestand:http://localhost/oe/oe_211.html
Regel: 10
BTW: regel 10 is dutch for line 10 which is the line with if (request.status
== 200).

The strange thing is that the AJAX works well (i get the message), but in
Firefox and in Internet Explorer I get error codes.

I have the following code:
oe_211.html:
<html>
<head>
<title></title>
<script type="text/javascript">
function makeRequest()
{
var request=new XMLHttpRequest();
request.open("GET","oe_212.php");
request.onreadystatechange=function() {
if (request.status == 200)
{
if (request.readyState == 4)
{
var obj=document.getElementById("content");
obj.childNodes[0].data=request.responseText;
}
else
{
// nothing
}
}
else
{
// nothing
}
}
request.send(null);}

</script>
</head>
<body>
<p id="trigger">Click here</p>
<p id="content">!!!</p>
<script type="text/javascript">
triggerObj=document.getElementById("trigger");
triggerObj.addEventListener("click",makeRequest,false);
</script>
</body>
</html>

and the following code:
oe_212.php:
<?php
echo "Hello world!";
?>

What can be the problem?

With kind regards,

Dennis

Hi,

youre code will be executed on each "onreadystatechange" event, and
status will not be set on each changed readyState, but after an
compleeted request, this happens e. g. if readyState contains the
value 4. You should check first readyState and then status.

Changing the code as follws should solve the problem:
[snip]
...
if (request.readyState == 4)
{
if (request.status == 200)
{
var obj=document.getElementById("content");
obj.childNodes[0].data=request.responseText;
}
else
{
// nothing
}
}
else
{
// nothing
}
}
...
[/snap]

purcaholic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top