473,666 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assigning a CGI output to JavaScript variable.

How can I assign a return value of a CGI to a JavaScript variable? Or
what is the correct way?
<script>
var myData = eval(http://somewhere/cgi-bin/data.cgi");
</script>

TIA

Sam
Jul 20 '05 #1
1 8417


sams wrote:
How can I assign a return value of a CGI to a JavaScript variable? Or
what is the correct way?
<script>
var myData = eval(http://somewhere/cgi-bin/data.cgi");
</script>


You could use
<script type="text/javascript" src="/cgi-bin/whatever.cgi"></script>
and then let that CGI program generate
var myDate = "...data goes here...";
If you want to read in the output of someone's CGI program then in
general that is not doable as the same origin policy doesn't allow
access to another server.
If you have need to read in any page from your own server then some
browsers like IE5+/Win or Mozilla/Netscape 6/7 allow you to send a HTTP
request and receive the response including the response text. It doesn't
matter if you request a static HTML page or a CGI. For instance with
Mozilla you can do

var httpRequest = new XMLHttpRequest( );
httpRequest.ope n('GET', 'whatever.cgi', false);
httpRequest.sen d(null);
alert(httpReque st.responseText )

Note that the above requests the resource synchronously, meaning the
script waits for the response and the browser is blocked while doing the
request so you should do it asynchronously if you want the browser to
stay responsive:

var httpRequest = new XMLHttpRequest( );
httpRequest.ope n('GET', 'phpinfo.php', true);
httpRequest.onr eadystatechange = function (evt) {
if (httpRequest.re adyState == 4) {
alert(httpReque st.responseText );
}
};
httpRequest.sen d(null);
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10131
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and have the function update the target ID with the URL. There is a bit more to it then that, but that is the basics. my difficulty comes when I try to assign a variable to: "document.getElementById('-> var gose here <-').innerHTML"
20
6957
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
3
6781
by: stahl.karl | last post by:
I have a CGI/Perl program that returns a string output. Is it possible to get this into a Javascript variable, where the name of the variable is defined in the Javascript and not in the Perl code? For example, it seems that the following should work, but it doesn't appear to. Is this valid code? CGI code --- get_string.pl ------ print "Content-type: text/plain\n\n";
7
2524
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written several methods that are working fine. The problem is if I want to dynamically assign an event handler to the object, the event handler is not called. What am I doing wrong? Below is a sample HTML doc with everything in place. <!DOCTYPE HTML PUBLIC...
3
2017
by: Sandman | last post by:
Hello, I'm building a website in PHP and Javascript. The registration portion is divided into 2 sections: 1. In one, I get info about the visitor. This is sent via POST to a php script which is section 2. 2. In the second section, I get some specific information about their pets and make suggestions. I'm having problems with section 2, and I hope y'all can help. The core of the PHP script in Section 2 consists of the following:
2
5742
by: swapna | last post by:
Hi, I have one doubt in my project i.e i should keep the value of java variable to javascript variable. thanks in advance.
37
2655
by: miken32 | last post by:
In PHP, if a function returns an array it's fairly common to capture its return values like this: <?php list($foo, $bar, $baz) = some_function_that_return_an_array(); ?> In Javascript, would the equivalent (acceptable) code be this? = some_function_that_return_an_array();
3
2396
by: sasimca007 | last post by:
Hello friends, IN modperl we write perl with html,javascript and etc. when we are writing perl code in the middle of javascript and if we want to assign a javascript variable to a perl variable, how it is possible?(Without using Ajax). Urgent friends
7
1769
by: jodleren | last post by:
Hi I have been looking into php.net, but could not find any proper description. There is a way of assigning variables from functions, while at the same time using them in e.g. an if. I have tried to use this, but failed.... and I have not found any proper information about this? E.g., if I am right, then
0
8785
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8644
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5671
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.