[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Calling server side function from client side

Posted on 2002-06-11
7
Medium Priority
?
245 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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