xmlHttpRequest gives no response

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Laman

    xmlHttpRequest gives no response

    I have a problem with the following script code:

    function updateschedule( mth)
    {
    xmlHttp = CreateXmlHttp()
    try
    {
    xmlHttp.open("G ET", "schedule/maandroostertbl .php?mth="+mth,
    false)
    xmlHttp.send(nu ll)
    if(xmlHttp.read yState==4)
    {
    div = document.getEle mentById("sched ule")
    div.innerHTML = xmlHttp.respons eText
    }
    }
    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?
  • Tom de Neef

    #2
    Re: xmlHttpRequest gives no response


    "Peter Laman" <peter.laman@gm ail.com wrote
    >I have a problem with the following script code:
    >
    function updateschedule( mth)
    {
    xmlHttp = CreateXmlHttp()
    try
    {
    xmlHttp.open("G ET", "schedule/maandroostertbl .php?mth="+mth,
    false)
    xmlHttp.send(nu ll)
    if(xmlHttp.read yState==4)
    {
    div = document.getEle mentById("sched ule")
    div.innerHTML = xmlHttp.respons eText
    }
    }
    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


    Comment

    • venti

      #3
      Re: xmlHttpRequest gives no response

      On Apr 19, 5:18 am, Peter Laman <peter.la...@gm ail.comwrote:
      I have a problem with the following script code:
      >
      function updateschedule( mth)
      {
      xmlHttp = CreateXmlHttp()
      try
      {
      xmlHttp.open("G ET", "schedule/maandroostertbl .php?mth="+mth,
      false)
      xmlHttp.send(nu ll)
      if(xmlHttp.read yState==4)
      {
      div = document.getEle mentById("sched ule")
      div.innerHTML = xmlHttp.respons eText
      }
      }
      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.ph p
      <?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.

      Comment

      Working...