xmlHttpRequest gives no response

P

Peter Laman

I have a problem with the following script code:

function updateschedule(mth)
{
xmlHttp = CreateXmlHttp()
try
{
xmlHttp.open("GET", "schedule/maandroostertbl.php?mth="+mth,
false)
xmlHttp.send(null)
if(xmlHttp.readyState==4)
{
div = document.getElementById("schedule")
div.innerHTML = xmlHttp.responseText
}
}
catch(err)
{
alert('Het maandrooster kon niet worden opgehaald.')
}
}

CreateXmlHttp is a general, browser independent function I always use
to create the object. The mth parameter stands for a month number for
which to generate code. The returned text is expected to be HTML. I
tested this with the 'usbwebserver' local server and it works. But
after uploading the code to the 'real' website it does not give any
response and no exception either. When I request the referred resource
manually, it does give the expected response. Specifying a full URL
(http://...) in the xmlHttp.open call does not help.

What I don't understand is, that the functioning of this code depends
on the SERVER where it resides, because the client is the same.
However, the problem is not with the requested resource itself, since
I can access it manually.

Any ideas?
 
T

Tom de Neef

Peter Laman said:
I have a problem with the following script code:

function updateschedule(mth)
{
xmlHttp = CreateXmlHttp()
try
{
xmlHttp.open("GET", "schedule/maandroostertbl.php?mth="+mth,
false)
xmlHttp.send(null)
if(xmlHttp.readyState==4)
{
div = document.getElementById("schedule")
div.innerHTML = xmlHttp.responseText
}
}
catch(err)
{
alert('Het maandrooster kon niet worden opgehaald.')
}
}

CreateXmlHttp is a general, browser independent function I always use
to create the object. The mth parameter stands for a month number for
which to generate code. The returned text is expected to be HTML. I
tested this with the 'usbwebserver' local server and it works. But
after uploading the code to the 'real' website it does not give any
response and no exception either. When I request the referred resource
manually, it does give the expected response. Specifying a full URL
(http://...) in the xmlHttp.open call does not help.

What I don't understand is, that the functioning of this code depends
on the SERVER where it resides, because the client is the same.
However, the problem is not with the requested resource itself, since
I can access it manually.

Any ideas?

(CreateXmlHttp() will return a XMLHttpRequest object ?)
When xmlHttp can't access the resource, it will not throw an error. You will
have to test its status (eg 404 - not found).
The source you try to load must be in the same domain as the browser page.
Tom
 
V

venti

I have a problem with the following script code:

function updateschedule(mth)
{
xmlHttp = CreateXmlHttp()
try
{
xmlHttp.open("GET", "schedule/maandroostertbl.php?mth="+mth,
false)
xmlHttp.send(null)
if(xmlHttp.readyState==4)
{
div = document.getElementById("schedule")
div.innerHTML = xmlHttp.responseText
}
}
catch(err)
{
alert('Het maandrooster kon niet worden opgehaald.')
}

}

CreateXmlHttp is a general, browser independent function I always use
to create the object. The mth parameter stands for a month number for
which to generate code. The returned text is expected to be HTML. I
tested this with the 'usbwebserver' local server and it works. But
after uploading the code to the 'real' website it does not give any
response and no exception either. When I request the referred resource
manually, it does give the expected response. Specifying a full URL
(http://...) in the xmlHttp.open call does not help.

What I don't understand is, that the functioning of this code depends
on the SERVER where it resides, because the client is the same.
However, the problem is not with the requested resource itself, since
I can access it manually.

Any ideas?

Well when your ajax responseText is coming up empty, I always start by
passing back a hardcoded response from the php script. So at the end
of the php script instead of echoing the value from the db, just use
serverscript.php
<?php
echo "foobar";
?>
and make sure you echo the response and don't 'return' it. see if
this value is making back to the responseText. If it is, then you've
got parameter issues, or sql errors. if it's not making it back, then
you need to look at URLs/directory structure. In particular the HTML
page that contains this ajax code must live in a directory that also
contains your schedule directory.try putting them in the same
directory to start with.
 

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

Forum statistics

Threads
473,995
Messages
2,570,235
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top