Forum Moderators: open

Message Too Old, No Replies

How to assign URL query results to variables

         

frankc

5:04 am on Mar 25, 2009 (gmt 0)

10+ Year Member



Attempting to parse the query results to variables using Javascript. PHP is not available for use.

This is a bit unusual in that the values I need are obtained by querying a networked PTZ camera in this manner:

http://example.com/test-cgi/com/need.cgi?query=position

Typical results returned to the querying browser are:

camera=1 pan=-88 tilt=8 zoom=2266 focus=514 iris=2259

I need to display these values on a webpage in a format different from the above, but I am having one devil of a time understanding how to "submit" the above URL and to subsequently assign the returned values to Javascript variables to allow me to do so.

The URL needs to be "submitted" from within a function, i.e. not from a user's press of a form button.

I know I am missing a series of processes that will be obvious to you, but for the life of me, I can't get a handle on this.

Thank you for your time,
Frank

daveVk

5:29 am on Mar 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AJAX is what you need. Check w3schools or search for "ajax tutorial" to get started.

Welcome Frank

frankc

3:04 pm on Mar 25, 2009 (gmt 0)

10+ Year Member



Thanks for the tip dave. I just read a little about AJAX, and it does seem to be heading in the right direction. I've seen AJAX and Javascript tied together in various articles but didn't realize that could be the key. I am assuming the reason Javascript doesn't work in this case is due to the need for pull of the information in effect rather than push (?)

Thanks again.

frankc

9:59 pm on Mar 25, 2009 (gmt 0)

10+ Year Member



I've been going through the tutorial for AJAX. However it seems that in order for AJAX to work, there is an asp file placed on the server that interacts with the Javascript script that would be accessed by the client. In my case, the Javascript app resides on the server accessed by the browser, but the data needed is in firmware on a second server. Am I misunderstanding how AJAX works?

My situation is that the "server" that I need data from is in firmware with no way to add an asp file.

Can someone give me a hint to shed light on where I should be heading with this?

Thanks.

Frank

daveVk

1:08 am on Mar 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The ajax get() request url is

http://example.com/test-cgi/com/need.cgi?query=position

and the ajax reply will be the string

camera=1 pan=-88 tilt=8 zoom=2266 focus=514 iris=2259

Provided the data can be accessed via a URL the source of the data is not important, there is no need for special files on the server.

frankc

1:53 pm on Mar 26, 2009 (gmt 0)

10+ Year Member



Thanks Dave.

I do have an AJAX script working now! And when I run it in IE & FF directly from my PC's C drive it fetches the data from the camera URL (same domain as my PC). But when I run it from its domain (an external host), I get a "Permission denied" error in IE and from FF I get:

"Security Error: Content at http://example.com/testajax3.html may not load data from http://<my WAN IP>/test-cgi/com/need.cgi?query=position."

and

"Error: uncaught exception: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "http://example.com/testajax3.html Line: 40"]"

However, within the same HTML file that holds the AJAX script, I have an iframe with the same URL (including the WAN IP) as in the AJAX get statement and it displays the results properly. It seems AJAX isn't dealing with the cross-domain aspect of this, whereas the iframe does. Does that make any sense?

AJAX certainly appears to be appropriate for this application as per your advice. However, I'm not real sure I can get around this latest issue.

Thanks again for your time and support.

Frank

[edited by: DrDoc at 4:54 pm (utc) on April 8, 2009]
[edit reason] delinked example URI [/edit]

daveVk

2:26 am on Mar 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cross domain restriction are a pain. As you say using the iframe will let you see the data, but try and read or manipulate it and the same restrictions apply.

If it just for yourself and friends your can change you browser setting.

If just working with the latest browsers is Ok. I understand there are new meta tags that can be used to allow cross domain working, but as you can not change the server that is probably not an option.

google "cross domain ajax" will find other techniques but not sure any fit your case. Perhaps the "flash" solution.

frankc

4:02 am on Mar 27, 2009 (gmt 0)

10+ Year Member



Ok. Thanks Dave. what a deal! Now that I somewhat understand the issue, I can go forward. I was really dazed and confused when nothing I tried worked and I didn't know why.

As far as iframe is concerned, it seems to dispaly all right. But I know of know way to manipulate the data. I had been planning to build a graphic representation of camera position. So the iframe display does no good.

But AJAX is interesting. I appreciate your advice in that regard and plan to pursue it more. Also have heard about JQUERY and need to look into that.

Thanks again,
Frank

daveVk

5:54 am on Mar 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JQUERY framework is worth a look, it makes AJAX simple, but don't think it helps with cross domain issue.

Iframes can achieve most of what newer AJAX methods do and is supported by older browsers, the cross domain restriction in this case accessing its content, you need something on the some domain to assist possibly a second iframe.

frankc

12:47 pm on Mar 27, 2009 (gmt 0)

10+ Year Member



OK Dave, I'll look into that. I'm also considering hosting the webpage on one of my computers. That would keep the domain the same as the camera. I haven't tried it, but that would eliminte the cross domain issue. I would use the same AJAX script that I have almost finished. I've got the data parsed and am contructing the graphic representation.

Thanks for the advice!
Frank

frankc

8:05 pm on Mar 27, 2009 (gmt 0)

10+ Year Member



Well, it seems even though I host the website on my server, since it isn't a website within the camera, it is still considered a cross domain issue. So I still get permission denied. I've read that some browsers can be configured to circumvent that, but that would need to be done manually at the browser location. So it seems I am back to square one. However, now, I am beginning to think it can't be done. Albeit, "impossible" seems unlikely.

Thanks for the help.

daveVk

1:35 am on Mar 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try setting document.domain say

document.domain = "example.com";

with camera on say camera.example.com and page on www.example.com

frankc

2:49 pm on Mar 31, 2009 (gmt 0)

10+ Year Member



Dave,

Thanks for advice.... the document.domain function was a good one and seems appropriate, but I couldn't get access to the data. I believe the reason is that I have to use a port number on the IP. I have the WAN hitting a router and the camera and servers connect to the router. So I have to assign ports for forwarding.

Seems strange to think that getting the data from the camera in such a way that to do anything but display it is impossible! iFrame works for the display, but still no way to even format the iframe's content.

Thanks for your support Dave.

Frank

daveVk

1:14 am on Apr 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Frank

Can you give more details on the form of the urls you are using, is it same domain name, different port or whatever.

Is set up a proxy on the page server to forward data from camera server an option ?. This is a common workaround.

Alternatively the page server could access camera and do formatting server side.

Dave

frankc

1:55 pm on Apr 2, 2009 (gmt 0)

10+ Year Member



Dave, here are details I think answers your first question...

The camera firmware server is WAN IP (example) 356.12.230.43:80 or LAN at 192.168.1.8

I am trying to get the camera GET data from a webpage stored on computer at WAN IP 356.12.230.43:81 / LAN 192.168.1.103

AJAX Get works fine when opening the php file in the browser from the PC (192.168.1.103) serving the webpage. But from another PC on the LAN side, 192.168.1.102, Permission Denied type errors are returned.

I don't yet understand the process of "proxy on the page server" or "formatting server side". However your two or three previous tips were very appropriate and showed great promise. So I look forward to understanding and experimenting with your most recent ideas. The "serving" PC runs Windows XP... It has no actual serving software. Perhaps that is a problem with your most recent proposed solutions (?)

Thanks for your interest Dave. Your comment of "common workaround" leads me to believe that you still think there is a way to do this.

Frank

[edited by: DrDoc at 4:56 pm (utc) on April 8, 2009]
[edit reason] replacing real IPs with bogus ones [/edit]

daveVk

5:28 am on Apr 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I take it you are using urls like [192.168.1.103...] that have the IP hard coded as opposed to [camera.example.com...] where camera.example.com is the DNS entry for 192.168.1.103

Is there a domain name server (DNS) setup on your network so that machines can be addressed by name rather than IP, where the name has two parts camera.example.com the subdomain (per machine) and the domain (per group of machines) ?

frankc

1:45 pm on Apr 4, 2009 (gmt 0)

10+ Year Member



Hi Dave. I apologize for not covering that side of the issue. I do have a redirect from DynDNS directly to the camera i.e. http://frank.example.com (the Host entry) that points directly to http://356.12.230.43. And since the camera is on port 80, that redirect goes directly to the camera.

Then I have a redirect that points to the serving PC's port number... i.e. http://frank.example.com:83. So when my dynamic IP changes both redirects change as well (however my "dynamic IP" hasn't changed for well over a year). That redirect accesses the serving program on that PC.

Did I cover the full picture? And I can always change any of those if that would help. People really don't even access the camera using a redirect. People access the camera by going through my main webpage, which is an actual domain name... i.e. http://www.example.com, which is a php webpage residing on my host provider's server. On that page is a link to the server PC. Then on the program (WebCamXP) running on the server PC is an option to view the camera feed.

Thanks for your help with this Dave and for suffering through all of that!

Frank

[edited by: DrDoc at 4:59 pm (utc) on April 8, 2009]
[edit reason] examplifying URIs and IPs [/edit]