473,388 Members | 1,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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?
var myData = eval(http://somewhere/cgi-bin/data.cgi");


Jul 20 '05 #1
1 8401

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

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.open('GET', 'whatever.cgi', false);

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.open('GET', 'phpinfo.php', true);
httpRequest.onreadystatechange = function (evt) {
if (httpRequest.readyState == 4) {

Martin Honnen

Jul 20 '05 #2

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

Similar topics

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...
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 =...
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?...
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...
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...
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.
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...
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...
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...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
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...

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.