xmlHttpRequest is not working

Discussion in 'Javascript' started by eulaersivan@yahoo.com, Jan 19, 2007.

  1. Guest

    I would like to use the xmlhttprequest-object to send an http request
    to my server. The http request is used to switch the light on through
    home automation.

    However it's not working, and I can't find the problem.

    Could it be that the apache-server is located on 192.168.0.21 and that
    the http request is sent to 192.168.0.21:8080?

    Thanks for your help.

    Ivan

    This is my code:

    <script type="text/javascript">
    var xmlhttp

    function loadXMLDoc(eibMessage)
    {
    var url='http://192.168.0.21:8080/eibhomeserver?instruction=<eib
    type="write" path="/eib/groups/' + eibMessage + '/curvalue" data="1"/>'
    xmlhttp=null
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
    xmlhttp=new XMLHttpRequest()
    }
    // code for IE
    else if (window.ActiveXObject)
    {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    if (xmlhttp!=null)
    {
    // alert(url)
    xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,true)
    xmlhttp.send(null)
    }
    else
    {
    alert("Your browser does not support XMLHTTP.")
    }
    }

    function state_Change()
    {
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4)
    {
    // if "OK"
    if (xmlhttp.status==200)
    {
    // ...some code here...
    alert("loaded")
    }
    else
    {
    alert("Problem retrieving XML data")
    }
    }
    } else {
    alert(xmlhttp.readyState)
    }
    </script>
     
    , Jan 19, 2007
    #1
    1. Advertising

  2. ASM Guest

    a écrit :
    >
    > function loadXMLDoc(eibMessage)
    > {
    > var url='http://192.168.0.21:8080/eibhomeserver?instruction=<eib
    > type="write" path="/eib/groups/' + eibMessage + '/curvalue" data="1"/>'


    I don't know what it is :

    <eib type="write" path="/eib/groups/'+eibMessage+'/curvalue" data="1"/>'

    nor what it is supposed to do


    all rest seems OK


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Jan 19, 2007
    #2
    1. Advertising

  3. wrote:
    > I would like to use the xmlhttprequest-object to send an http request
    > to my server. The http request is used to switch the light on through
    > home automation.
    >
    > However it's not working, and I can't find the problem.
    >
    > Could it be that the apache-server is located on 192.168.0.21 and that
    > the http request is sent to 192.168.0.21:8080?


    Check the JavaScript console? Do you get a permission denied error? The
    same origin policy might prevent you from connecting to that port.
    If all you want is to make a GET request then e.g.
    var httpRequest = new Image();
    httpRequest.src = 'http://example.com/whatever?arg1=val1&arg2=val2';
    might suffice and not be restricted by the same origin policy.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 20, 2007
    #3
  4. Guest

    Thanks for your help. It was indeed a security issue.

    I've solved it by adding a proxy in my apache configuration. So I
    request a page from the same server, but apache forwards it to port
    8080.

    Thank you

    Ivan
     
    , Jan 20, 2007
    #4
  5. psema4 Guest

    wrote:
    > Thanks for your help. It was indeed a security issue.
    >
    > I've solved it by adding a proxy in my apache configuration. So I
    > request a page from the same server, but apache forwards it to port
    > 8080.


    That's interesting. I know several folks who are involved in projects
    related to system/home automation.

    It looks like your automation softare is not running directly through
    your standard web-server software (Apache?).

    If not, running a reverse proxy through Apache would certainly do the
    job -- I've used this method numerous times.

    I am curious however as to the automation server software you're using
    though. Currently I'm participating in the "ICP" (iCanProgram)
    "Introduction to Linux Programming" course*. A package/API called
    "SIMPL" is introduced during the course, and is referenced elsewhere on
    the internet as being a capable home-automation tool.

    Anyway, I'm just asking for knowledge's sake. Take care, best-of-luck,
    and glad-you-found-a-solution! =)
    - Scott.

    * The course starts every couple of months (free with a donation to
    your local Cancer Society) and can be found at:
    http://www.icanprogram.com/43ux/main.html
     
    psema4, Jan 20, 2007
    #5
  6. wrote:
    > Thanks for your help. It was indeed a security issue.
    >
    > I've solved it by adding a proxy in my apache configuration. So I
    > request a page from the same server, but apache forwards it to port
    > 8080.


    So you are now really turning on your lights at home through a website?
    Must be some fancy home admin page you have if you want Ajax for this.
    I'm curious why you need to do this but maybe that's none of my
    business.

    Peter
     
    Peter Michaux, Jan 20, 2007
    #6
  7. Guest

    FYI:

    I'm using the EIB home automation which is a standard among 100 brands
    (Siemens, Gira, Merten, ..). There are several open source programs
    available to connect to the bus. I'm starting to use the eibcontrol
    server.

    This server responds to httprequests on port 8080.

    Within the server there are some examples to shut on/off the lights,
    but to avoid that the user shifts from the current page when sending an
    httprequest, they use frames.

    I prefer a more modern solution, so that why I as looking at the
    xmlhttprequest-object.

    My goal is to have a web-app so I can control lighting from the coach.
    Remote control is not my goal, but it is possible. 5 min. ago a friend
    was able to put on my lights. But ofcourse ... I still have to put
    security in place.

    To control the lights, I'll use the Nokia 770 web browser (or perhaps
    the iPhone in a couple of years :)

    Ivan
     
    , Jan 21, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QnJhdm8=?=

    XMLHTTPRequest with Xpath is not working

    =?Utf-8?B?QnJhdm8=?=, Apr 1, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    553
    =?Utf-8?B?QnJhdm8=?=
    Apr 1, 2004
  2. Unknown User

    XMLHttpRequest not working as expected

    Unknown User, Feb 7, 2005, in forum: Javascript
    Replies:
    2
    Views:
    96
    Unknown User
    Feb 8, 2005
  3. xmlhttprequest not working

    , Sep 21, 2005, in forum: Javascript
    Replies:
    4
    Views:
    172
  4. VK
    Replies:
    3
    Views:
    108
    Jim Ley
    Apr 6, 2006
  5. Replies:
    1
    Views:
    116
    Laurent Bugnion
    Jun 9, 2006
Loading...

Share This Page