xmlHttpRequest is not working

E

eulaersivan

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>
 
M

Martin Honnen

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.
 
E

eulaersivan

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
 
P

psema4

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
 
P

Peter Michaux

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
 
E

eulaersivan

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top