|
From: Peter Laman on 19 Apr 2008 05:18 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?
From: Tom de Neef on 19 Apr 2008 06:00 "Peter Laman" <peter.laman(a)gmail.com> wrote >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
From: venti on 19 Apr 2008 20:27 On Apr 19, 5:18 am, Peter Laman <peter.la...(a)gmail.com> wrote: > 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.
|
Pages: 1 Prev: how to refer to a form element? Next: meaning of "===" for objects ??? |