Jump to content

Anyone understand what is going on in this script?


Recommended Posts

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html>
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function TestId() {
WebService1.GetAppId(onSuccess, onFailure);
}
//situation 1
function onSuccess(result) {
alert(result);
}
//situation 2
//function onSuccess(result) {
// return result;
//}
function onFailure(result) {
alert("Error Invoking the Web Service...");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="scriptManager">
<Services>
<asp:ServiceReference
Path="~/WebService1.asmx" />
</Services>
</asp:ScriptManager>
<div>
<video id="localVideo" style="width: 300px; height: auto;" autoplay muted></video>
</div>
</form>
<script type="text/javascript">
TestId(); // This line is working in situation 1 (onSuccess method situation 1)
//BUT, WHEN I COMMENT METHOD IN SITUATON 1 AND UNCOMMENT SITUATION2 THEN LINE BELOW IS NOT WORKING
var a = TestId(); //THIS LINE IS NOT WORKING WHEN SITUATION2 IS ACTIVE
</script>
</body>
</html>
Link to post
Share on other sites

What do you mean it is not working? What exactly do you expect to happen, and what is actually happening? If you expect the TestId function to return the result from the onSuccess function, that will not happen.

Link to post
Share on other sites

well for one thing testId() doesn't have a return command so "var a" will always be undefined. add a return statement in testId() and start working from there.

function TestId() {     return WebService1.GetAppId(onSuccess, onFailure);}
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...