Jump to content

JavaScript Functions That Call WebService Methods Are Not Working


Recommended Posts

Hello,
very simple code block is below. Javascript functions that call web service methods are working when I called them between form tags. But they are not working at the beginning of the page.
I specified lines that are not working below.
Please help.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<head runat="server">
<title></title>
<script type="text/javascript">
function GetMyName() {
WebService1.GetName(onNameSuccess, onNameFailure);
}
function onNameSuccess(result) {
return result;
}
function onNameFailure(result) {
alert("There is an error");
}
function GetMySurname() {
WebService1.GetSurname(onSurnameSuccess, onSurnameFailure);
}
function onSurnameSuccess(result) {
return result;
}
function onSurnameFailure(result) {
alert("There is an error");
}
//JAVASCRIPT FUNCTIONS ARE NOT WORKING HERE
//THESE TWO LINES ARE NOT WORKING
var name = GetMyName();
var surname = GetMySurname();
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService1.asmx" />
</Services>
</asp:ScriptManager>
//JAVASCRIPT FUNCTIONS ARE WORKING HERE
</form>
</body>
</html>
Link to post
Share on other sites

This looks like server-side Javascript.

 

The variable "WebService1" is not defined in the head. Try moving the ASP ScriptManager lines up to the head section before the rest of the Javascript.

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...