Solved

Calling server side function from client side

Posted on 2002-06-11
7
238 Views
Last Modified: 2012-05-04
How to call server-side function from client side without posting response. Sample code below

<%@ Language=VBScript %>
<%
function ShowMe()
  Response.write "Hello world!!!"
end function
%>
<html>
<body>
<form name="Form1" method=post action=myasp.asp>
<input type="button" name="load" value="load" onclick="javascript:ff();">
</form>
</body>
</html>
<script LANGUAGE="JavaScript">
function ff()
{
     eval("<%zz = ShowMe()%>")
     alert(zz);
}
</script>
0
Comment
Question by:sanjuo
7 Comments
 
LVL 1

Expert Comment

by:choroque
ID: 7071679
<%@ Language=VBScript %>
<%
function ShowMe()
 Response.write "Hello world!!!"
end function
%>
<html>
<body>
<form name="Form1" method=post action=myasp.asp>
<input type="button" name="load" value="load" onclick="javascript:ff();">
</form>
</body>
</html>
<script LANGUAGE="JavaScript">
function ff()
{
    <%zz = ShowMe()%>
    alert('<%=zz%>');
}
</script>
0
 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 7072051
You cannot execute a function on the server without a roundtrip to the server.
0
 
LVL 11

Accepted Solution

by:
ASPGuru earned 30 total points
ID: 7072160
choroque, your code will not work...

sanjuo, wboevink is right, actually...
you can't really...

of course i can make your code work the way you expect it, but only by calling the function _before_ sending the data to the browser... have a look at this:

<%@ Language=VBScript %>
<%
function ShowMe()
 ShowMe = "Hello world!!!"
end function
%>
<html>
<body>
<form name="Form1" method=post action=myasp.asp>
<input type="button" name="load" value="load" onclick="javascript:ff();">
</form>
</body>
</html>
<script LANGUAGE="JavaScript">
function ff()
{
    alert("<%=ShowMe()%>");
}
</script>

ASPGuru
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:sanjuo
ID: 7072985
First thank all for your efforts,

ASPGuru,

I want the server-side function get executed when you press button not before that.

I saw some code which uses xmlhttp service to overcome this problem. Really I did not understand that code and I lost that link also. I will try to find that link. Let you know.
0
 
LVL 3

Expert Comment

by:dragosh
ID: 7073009
hi there

here is a simple example of using XMLHTTP :


demo.asp
========

<%@ Language=VBScript %>
<HTML>
<HEAD>
<script language="javascript">
<!--
function doAction()
{
     var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
     xmlhttp.open("POST", "action.asp?action=X", false);
     xmlhttp.send("text");
     mydiv.innerHTML = xmlhttp.Responsetext;
}

// -->
</script>
</HEAD>
<BODY>

<P>xmlhttp demo</P>


<input type="button" name="btnAction" value="action" onclick="javascript:doAction();">
<div id="mydiv"></div>

</BODY>
</HTML>

action.asp
==========

<%@ Language=VBScript %>
<%

If Request.QueryString("action") = "X" Then
     Response.Write Request.ServerVariables("REQUEST_METHOD")
Else
     Response.Write Request.TotalBytes
End If
%>


i hope this will help
0
 
LVL 11

Expert Comment

by:ASPGuru
ID: 7073169
XMLHTTP will only work in IE and NS6 maybe...

is this ok for you?

ASPGuru
0
 
LVL 4

Expert Comment

by:Wakie
ID: 9142969
It appears this question has been abandoned.

I will leave a recommendation in the Cleanup topic area that this question will be:

- Question PAQ'd and points to ASPGuru -

Please leave any comments here within the next seven days.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Wakie,
EE Cleanup Volunteer.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now