473,729 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP Page as Remote Function call from Javascript

Hello,

I've been playing with the idea of just how to use an ASP page to provide a
remote function call. In an ideal world this would be a web service but how
can you do it if restricted to ASP 3.0 ?

Idea 1 was to write an ASP page that accepted arguments using the classic
?X=1&Y=2 type of strings and have the page return an ADO disconnected record
set containing the results of the action. This is call very well, and works,
but you do have to allow the browser to create an ADODB.RecordSet in which
to place the results which goes against some security principles.

Idea 2 was to use an <IFRAME> and replace the src for this frame at run time
with the result from an ASP page, again using the ?X=1&Y=2 type of string to
pass in arguments. The results could then come back as a table and be
accessed via the DOM. The problem with this is that the client needs to wait
for the page to be loaded before it can be sure that the contents of the
table is valid and the browser does not seem to allow waits and does not
like busy waits.

Idea 3 - I'm still looking for this ! Does anyone have any ?

Many thanks

Martin
Jul 19 '05 #1
9 5728
Martin Waller wrote:
Hello,

I've been playing with the idea of just how to use an ASP page to
provide a remote function call. In an ideal world this would be a web
service but how can you do it if restricted to ASP 3.0 ?

Idea 1 was to write an ASP page that accepted arguments using the
classic ?X=1&Y=2 type of strings and have the page return an ADO
disconnected record set containing the results of the action. This is
call very well, and works, but you do have to allow the browser to
create an ADODB.RecordSet in which to place the results which goes
against some security principles.

Idea 2 was to use an <IFRAME> and replace the src for this frame at
run time with the result from an ASP page, again using the ?X=1&Y=2
type of string to pass in arguments. The results could then come back
as a table and be accessed via the DOM. The problem with this is that
the client needs to wait for the page to be loaded before it can be
sure that the contents of the table is valid and the browser does not
seem to allow waits and does not like busy waits.

Idea 3 - I'm still looking for this ! Does anyone have any ?

Many thanks

Martin


If I understand correctly what you're after, then the answer is XMLHTTP.
Google should supply the rest ...

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #2
Hello,

Many thanks for the reply but I'm not sure how that gets around having to do
something like:

x = new ActiveXObject(" Microsoft.XMLHT TP");

in the JavaScript which requires the setting / unsetting of a security
option in the browser ?

Martin

"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:u$******** ******@tk2msftn gp13.phx.gbl...
Martin Waller wrote:
Hello,

I've been playing with the idea of just how to use an ASP page to
provide a remote function call. In an ideal world this would be a web
service but how can you do it if restricted to ASP 3.0 ?

Idea 1 was to write an ASP page that accepted arguments using the
classic ?X=1&Y=2 type of strings and have the page return an ADO
disconnected record set containing the results of the action. This is
call very well, and works, but you do have to allow the browser to
create an ADODB.RecordSet in which to place the results which goes
against some security principles.

Idea 2 was to use an <IFRAME> and replace the src for this frame at
run time with the result from an ASP page, again using the ?X=1&Y=2
type of string to pass in arguments. The results could then come back
as a table and be accessed via the DOM. The problem with this is that
the client needs to wait for the page to be loaded before it can be
sure that the contents of the table is valid and the browser does not
seem to allow waits and does not like busy waits.

Idea 3 - I'm still looking for this ! Does anyone have any ?

Many thanks

Martin


If I understand correctly what you're after, then the answer is XMLHTTP.
Google should supply the rest ...

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jul 19 '05 #3
How about this (uses framesets):

1. Main frame directs "communicat ion" frame to target asp page and then
directs itself to a "waiting" page.
2. Page generated by target asp page includes JavaScript code to redirect
main frame back to original state.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Martin Waller" <Ma***********@ NOSPAN.com> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

Many thanks for the reply but I'm not sure how that gets around having to do something like:

x = new ActiveXObject(" Microsoft.XMLHT TP");

in the JavaScript which requires the setting / unsetting of a security
option in the browser ?

Martin

"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:u$******** ******@tk2msftn gp13.phx.gbl...
Martin Waller wrote:
Hello,

I've been playing with the idea of just how to use an ASP page to
provide a remote function call. In an ideal world this would be a web
service but how can you do it if restricted to ASP 3.0 ?

Idea 1 was to write an ASP page that accepted arguments using the
classic ?X=1&Y=2 type of strings and have the page return an ADO
disconnected record set containing the results of the action. This is
call very well, and works, but you do have to allow the browser to
create an ADODB.RecordSet in which to place the results which goes
against some security principles.

Idea 2 was to use an <IFRAME> and replace the src for this frame at
run time with the result from an ASP page, again using the ?X=1&Y=2
type of string to pass in arguments. The results could then come back
as a table and be accessed via the DOM. The problem with this is that
the client needs to wait for the page to be loaded before it can be
sure that the contents of the table is valid and the browser does not
seem to allow waits and does not like busy waits.

Idea 3 - I'm still looking for this ! Does anyone have any ?

Many thanks

Martin


If I understand correctly what you're after, then the answer is XMLHTTP.
Google should supply the rest ...

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Jul 19 '05 #4
Hello,

One way I've found to get away from the requirement in JavaScript to perform
the new ActiveXObject call is to put the object in the HTML page as it gets
sent to the client and then have the JavaScript call that. See below for an
example. To run this the URL will need to be changed to reflect where you
put it ! In my case it was called junk.asp...

<html>
<head>
<script language="JavaS cript">

function Do()
{
alert("Do()");
penguin.open("g et","http://localhost/smartanalysis/junk.asp",false );
alert(1);
penguin.send();
alert(2);
alert(penguin.r esponseText);
}

</script>
<object
classid="clsid: F6D90F16-9C73-11D3-B32E-00C04F990BB4"
id="penguin">
</object>
</head>
<body onLoad = "Do()">
</body>
</html>

Martin
"Mark Schupp" <ms*****@ielear ning.com> wrote in message
news:u$******** *****@TK2MSFTNG P15.phx.gbl...
How about this (uses framesets):

1. Main frame directs "communicat ion" frame to target asp page and then
directs itself to a "waiting" page.
2. Page generated by target asp page includes JavaScript code to redirect
main frame back to original state.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Martin Waller" <Ma***********@ NOSPAN.com> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

Many thanks for the reply but I'm not sure how that gets around having
to do
something like:

x = new ActiveXObject(" Microsoft.XMLHT TP");

in the JavaScript which requires the setting / unsetting of a security
option in the browser ?

Martin

"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:u$******** ******@tk2msftn gp13.phx.gbl...
Martin Waller wrote:
> Hello,
>
> I've been playing with the idea of just how to use an ASP page to
> provide a remote function call. In an ideal world this would be a web > service but how can you do it if restricted to ASP 3.0 ?
>
> Idea 1 was to write an ASP page that accepted arguments using the
> classic ?X=1&Y=2 type of strings and have the page return an ADO
> disconnected record set containing the results of the action. This is > call very well, and works, but you do have to allow the browser to
> create an ADODB.RecordSet in which to place the results which goes
> against some security principles.
>
> Idea 2 was to use an <IFRAME> and replace the src for this frame at
> run time with the result from an ASP page, again using the ?X=1&Y=2
> type of string to pass in arguments. The results could then come back > as a table and be accessed via the DOM. The problem with this is that > the client needs to wait for the page to be loaded before it can be
> sure that the contents of the table is valid and the browser does not > seem to allow waits and does not like busy waits.
>
> Idea 3 - I'm still looking for this ! Does anyone have any ?
>
> Many thanks
>
> Martin

If I understand correctly what you're after, then the answer is XMLHTTP. Google should supply the rest ...

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Jul 19 '05 #5
"Martin Waller" wrote:
I've been playing with the idea of just how to use an ASP page to provide a remote function call. In an ideal world this would be a web service but how can you do it if restricted to ASP 3.0 ?
Idea 3 - I'm still looking for this ! Does anyone have any ?


I'm making some assumptions here, but I think: you want the browser to get
some data that the server has. You want the browser to make a client-side
call to get this data without the current page being reloaded. And you
would
like this to be reasonably cross-browser compliant, and not require any
funky
client objects (ActiveXObjects , Object tags, XMLHTTP, etc).

If the above is correct, then this cool trick might work for you.
Put this function on your "main" page:

function getNewJSFile(qu erystring) {
var s = document.create Element("script ");
s.setAttribute( "src", "http://you.com/ReturnsJavascri ptArray.asp?" +
querystring);
s.setAttribute( "type", "text/javascript");
document.getEle mentsByTagName( "head")[0].appendChild(s) ;
}

That function above is ordinary JavaScript which works in almost all
browsers. (No Netscape 4 or earlier) Now, you can add calls to
getNewJSFile() on your "main" page like this:

<a href="javascrip t:getNewJSFile( 'yr=1999&data=s ales')">Show 1999
Sales</a>
<a href="javascrip t:getNewJSFile( 'yr=2000&data=s ales')">Show 2000
Sales</a>

When a user clicks these links, a new Javascript file will be downloaded
by the client. But, the file is actually an ASP3.0 page
(ReturnsJavascr iptArray.asp)
which returns Javascript. This allows you to query a database and format
the
response as a Javascript array, like this:

Sales_1999(1, 'Jan', '$234.56');
Sales_1999(2, 'Feb', '$123.45');
Sales_1999(3, 'Mar', '$456.78');

The response can even include functions and function calls:

function show_Sales_1999 () {
...code to loop thru array and alert() the sales data
}
show_Sales_1999 ()

Good Luck!
-Rob
Jul 19 '05 #6
Rob,

Nice one !

It seems to work but the one thing I'm not sure about is wether the
appendChild() operation is synchronous or not ? Do you have any idea ?

Many thanks...

Martin

"goinoutwes t" <go*********@ho tmail.com> wrote in message
news:uG******** ******@TK2MSFTN GP09.phx.gbl...
"Martin Waller" wrote:
I've been playing with the idea of just how to use an ASP page to
provide a
remote function call. In an ideal world this would be a web service but

how
can you do it if restricted to ASP 3.0 ?
Idea 3 - I'm still looking for this ! Does anyone have any ?


I'm making some assumptions here, but I think: you want the browser to get
some data that the server has. You want the browser to make a client-side
call to get this data without the current page being reloaded. And you
would
like this to be reasonably cross-browser compliant, and not require any
funky
client objects (ActiveXObjects , Object tags, XMLHTTP, etc).

If the above is correct, then this cool trick might work for you.
Put this function on your "main" page:

function getNewJSFile(qu erystring) {
var s = document.create Element("script ");
s.setAttribute( "src", "http://you.com/ReturnsJavascri ptArray.asp?" +
querystring);
s.setAttribute( "type", "text/javascript");
document.getEle mentsByTagName( "head")[0].appendChild(s) ;
}

That function above is ordinary JavaScript which works in almost all
browsers. (No Netscape 4 or earlier) Now, you can add calls to
getNewJSFile() on your "main" page like this:

<a href="javascrip t:getNewJSFile( 'yr=1999&data=s ales')">Show 1999
Sales</a>
<a href="javascrip t:getNewJSFile( 'yr=2000&data=s ales')">Show 2000
Sales</a>

When a user clicks these links, a new Javascript file will be downloaded
by the client. But, the file is actually an ASP3.0 page
(ReturnsJavascr iptArray.asp)
which returns Javascript. This allows you to query a database and format
the
response as a Javascript array, like this:

Sales_1999(1, 'Jan', '$234.56');
Sales_1999(2, 'Feb', '$123.45');
Sales_1999(3, 'Mar', '$456.78');

The response can even include functions and function calls:

function show_Sales_1999 () {
...code to loop thru array and alert() the sales data
}
show_Sales_1999 ()

Good Luck!
-Rob

Jul 19 '05 #7
"Martin Waller" wrote:
Rob,

Nice one !

It seems to work but the one thing I'm not sure about is wether the
appendChild() operation is synchronous or not ? Do you have any idea ?

Many thanks...

Martin


appendChild() is synchronous. But, I don't think when you use it to append
a new script block to the HEAD of a webpage that the code execution stops
and waits for the browser to "see" this new script block and finish
downloading
the file referenced as the SRC of the script block. (did that make sense?)

I have not tested this, but it should be easy to confirm.
-r
Jul 19 '05 #8
Rob,

I tried it and as you say the execution does not stop so the loading of the
script is happening after I'm testing for the results so I can't really use
that technique !

Many thanks for trying...

Martin

"goinoutwes t" <go*********@ho tmail.com> wrote in message
news:#x******** *****@TK2MSFTNG P11.phx.gbl...
"Martin Waller" wrote:
Rob,

Nice one !

It seems to work but the one thing I'm not sure about is wether the
appendChild() operation is synchronous or not ? Do you have any idea ?

Many thanks...

Martin

appendChild() is synchronous. But, I don't think when you use it to

append a new script block to the HEAD of a webpage that the code execution stops
and waits for the browser to "see" this new script block and finish
downloading
the file referenced as the SRC of the script block. (did that make sense?)
I have not tested this, but it should be easy to confirm.
-r

Jul 19 '05 #9
"Martin Waller" wrote:
I tried it and as you say the execution does not stop so the loading of the script is happening after I'm testing for the results so I can't really use that technique !


That's part of the trick. You probably have some function which handles
the task of "testing for results", right?

You need to put the call to that function as the last line of that newly
downloaded Javascript file.
For example, here is a simplified version of the "main" page:
<html>
<a href="javascrip t:getNewJSFile( 'data=sales')"> Show Sales</a>
<script>
function getNewJSFile(qu erystring) {...}
function handleNewData(a rrayName) {...}
</script>
</html>

And here's a simplified version of that new javascript file that will be
downloaded when that link is clicked:
/* begin code */
SalesData(1, '$234.56');
SalesData(2, '$123.45');
SalesData(3, '$456.78');
handleNewData(' SalesData');
/* end code */

So, you can see that the data will arrive just before the call to the
function
which is designed to handle that data. It will always work! My guess is
that you were doing something equivalent to this:
<a
href="javascrip t:getNewJSFile( 'data=sales');h andleNewData('S alesData');">Sh o
w Sales</a>
In that case, the call to handle the data is going to happen before the data
arrives.
That's bad.

-Rob
Jul 19 '05 #10

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

Similar topics

3
4052
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the onChange() or Click() does not do anything. It only seems to fire the onchange if I
2
7676
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
1
2404
by: nabilo | last post by:
I want to know if it's possible to call, within my cgi page, using javascript, a remote url and get the result without changing my actual page. To say more, I have a page result appaired to the customer. And I want to call, during this, a remote server to send the result of the operation (ok/nok). I don't want to use 'window.open' because it can be blocked by the browser (pop-up).
1
6020
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the browser back button, it loads the progress bar again. Any solution to this?
7
3264
by: John | last post by:
Hi I have forgotten how to do this. Got a <form ... > with <input type="button" name="Hit Me" onclick="whatever()"> </form> The output of the Javascript function 'whatever' appears on a separate
6
4892
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
4
1450
by: andre.roberge | last post by:
I'm using a js script (approx. 300 lines) from someone else to create dynamically some web pages, using Python. Unfortunately, I am not familiar with javascript :-( I now want to reproduce the same functionality given by the script at multiple points in the page. Basically, the script goes like this /* whole bunch of functions with things in them like input.value input.focus()
3
1459
by: windandwaves | last post by:
Hi Folk I am running a site (A) that has a US mirror (B). This means that all the data from A is copied daily to B. On the site, I keep some statistics of the pages people visit, tracking them with a session and noting their searches, etc... for statistical purposes. The problem I have is that if someone visits site B then at the end of
6
1837
by: Chris Beall | last post by:
(I'm rather inexperienced with JavaScript; the failing page was cobbled together from multiple sources)... http://pages.prodigy.net/chris_beall/STL/Timeline.html If JavaScript is not present, or CSS 2 isn't supported, the page just shows a complete list of dated entries. That's correct. If JavaScript is present and CSS 2 is supported, a subset of the list is shown (Example: 9 Jan 2008 is absent) and a button appears in the upper
0
8923
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8763
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9285
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
9203
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
8155
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3238
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
2686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
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.