?
Solved

Calling server side function from client side

Posted on 2002-06-11
7
Medium Priority
?
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 120 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

764 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