Reading data from remote URL

  • Thread starter news.west.cox.net
  • Start date
N

news.west.cox.net

Forgive me, I am new to javascript ( about 1 week playing with it ). I am
proficient in C, perl, python, java, etc... but no javascript.

I wrote an applet about 1 million years ago that has dynamic drop down
menus.

I have a couple of C programs that take GET requested data and displays
matching results from a database query...

For example... www.mydomain.com/cgi-bin/getTypes?code=6 might display
76|45|54|122|449|2020 and getTypes?code=7 might display 88|22|32|66|92

Now, I want to get that data into my javascript so I can break it down and
populate a drow down menu.

How can I retrieve this data?

Thanks for any help JS gurus.
 
M

McKirahan

news.west.cox.net said:
Forgive me, I am new to javascript ( about 1 week playing with it ). I am
proficient in C, perl, python, java, etc... but no javascript.

I wrote an applet about 1 million years ago that has dynamic drop down
menus.

I have a couple of C programs that take GET requested data and displays
matching results from a database query...

For example... www.mydomain.com/cgi-bin/getTypes?code=6 might display
76|45|54|122|449|2020 and getTypes?code=7 might display 88|22|32|66|92

Now, I want to get that data into my javascript so I can break it down and
populate a drow down menu.

How can I retrieve this data?

Thanks for any help JS gurus.

Will this help?

<html>
<head>
<title>getTypes.htm</title>
<script type="text/javascript">
function getTypes() {
var code = location.search;
code = code.charAt(code.length-1);
code = parseInt(code,10);
var list = new Array();
list[6] = "76|45|54|122|449|2020";
list[7] = "88|22|32|66|92";
var item = list
Code:
.split("|");
var form = document.forms[0];
form.Item.options.length = 0;
for (var i=0; i<item.length; i++) {
form.Item.options[i] = new Option(item[i],i);
}
}
</script>
</head>
<body onload="getTypes()">
<form>
<select name="Item">
</select>
</form>
</body>
</html>

Except that you would invoke it by:
www.mydomain.com/cgi-bin/getTypes.htm?code=6
not
www.mydomain.com/cgi-bin/getTypes?code=6
 
M

Martin Honnen

news.west.cox.net wrote:

I have a couple of C programs that take GET requested data and displays
matching results from a database query...

For example... www.mydomain.com/cgi-bin/getTypes?code=6 might display
76|45|54|122|449|2020 and getTypes?code=7 might display 88|22|32|66|92

Now, I want to get that data into my javascript so I can break it down and
populate a drow down menu.

How can I retrieve this data?

If you have server-side scripting then use it instead of JavaScript e.g.
build a CGI script that generates the necessary HTML for the <select>
and its <option> elements.
As for JavaScript making HTTP requests check
http://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616
and
http://jibbering.com/2002/4/httprequest.html
 
S

Sean Berry

Forgive me, I am new to javascript ( about 1 week playing with it ). I
am
proficient in C, perl, python, java, etc... but no javascript.

I wrote an applet about 1 million years ago that has dynamic drop down
menus.

I have a couple of C programs that take GET requested data and displays
matching results from a database query...

For example... www.mydomain.com/cgi-bin/getTypes?code=6 might display
76|45|54|122|449|2020 and getTypes?code=7 might display 88|22|32|66|92

Now, I want to get that data into my javascript so I can break it down
and
populate a drow down menu.

How can I retrieve this data?

Thanks for any help JS gurus.

Will this help?

<html>
<head>
<title>getTypes.htm</title>
<script type="text/javascript">
function getTypes() {
var code = location.search;
code = code.charAt(code.length-1);
code = parseInt(code,10);
var list = new Array();
list[6] = "76|45|54|122|449|2020";
list[7] = "88|22|32|66|92";
var item = list
Code:
.split("|");
var form = document.forms[0];
form.Item.options.length = 0;
for (var i=0; i<item.length; i++) {
form.Item.options[i] = new Option(item[i],i);
}
}
</script>
</head>
<body onload="getTypes()">
<form>
<select name="Item">
</select>
</form>
</body>
</html>
[/QUOTE]


I guess I was not clear.  Correct me if I am wrong ( and I hope I am ) but,
because JavaScript is client-side, it cannot make database querries.

Retrieving a results set from a database withing a Java Applet is a drawn
out, tedious task.  So, in an applet I wrote I use some intermediate C
programs to do the database querries and print the results.  In my applet I
open an http connection, send the URL, and read in the data printed to the
screen.  Then, I repopulate the drop downs with the results ( after I split
them up .)

I want to do this in javascript now...

I know how to populate drop downs like the example above shows... but how
can I go open a URL like .../cgi-bin/getTypes?code=24 and retrieve the data
within JS?

Thanks for any help
 
S

Sean Berry

If you have server-side scripting then use it instead of JavaScript e.g.
build a CGI script that generates the necessary HTML for the <select> and
its <option> elements.

This is something that I do all the time. But, in order to do that, my
script has to keep getting submitted with onchange="myform.submit();" calls.
I could have a perl script say... and in that script I have the value, label
option pairs in a hash. Then, when the select menu changes, the form is
submitted, and the next drop down is populated based on the new parameter
received. Then repeated for this second drop down.

But... I don't want the page to reload, I just want the drop downs to
repopulate without the browser refreshing.
 
M

Martin Honnen

Sean Berry wrote:

But... I don't want the page to reload, I just want the drop downs to
repopulate without the browser refreshing.

Use the links then I posted in my first reply, in some browsers (IE/Win,
Mozilla, Netscape, Safari 1.2) you can do HTTP request with script but
of course that will fail if someone tries to use your page with
JavaScript disabled or another browser not supporting XMLHttpRequest so
in the end you need to have your CGI solution nevertheless.
 
M

McKirahan

[snip]
I guess I was not clear. Correct me if I am wrong ( and I hope I am ) but,
because JavaScript is client-side, it cannot make database querries.

Retrieving a results set from a database withing a Java Applet is a drawn
out, tedious task. So, in an applet I wrote I use some intermediate C
programs to do the database querries and print the results. In my applet I
open an http connection, send the URL, and read in the data printed to the
screen. Then, I repopulate the drop downs with the results ( after I split
them up .)

I want to do this in javascript now...

I know how to populate drop downs like the example above shows... but how
can I go open a URL like .../cgi-bin/getTypes?code=24 and retrieve the data
within JS?

Thanks for any help

It sounds like you might want ASP (Active Server Pages) or comparable
technology.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top