Well missng
return false;
to the function
function CallService() {
Methodo_app.WebService1.HelloWorld("Yourself", onSuccess);
}
Question
I'm using Visual Studio 2012 to create a webapp.
I'm trying to create a webservice and call a function from javascript.
this is my webservice:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WebService1
Inherits System.Web.Services.WebService
<WebMethod()> _
public Function HelloWorld(ToSomeone As string ) As String
return "Hello World" + ToSomeone
End Function
End Class
and this is the call to the web service
<button class="customButton" onclick="return CallService()">ProvaWebService</button>
<div id="outputDiv" style="border: 1px solid black; height: 50px;"></div>
<script type="text/javascript">
function CallService() {
Methodo_app.WebService1.HelloWorld("Yourself", onSuccess);
}
function onSuccess(result) {
alert(result)
var outDiv = document.getElementById("outputDiv");
outDiv.textContent = result;
}
</script>
I think its all configured in the right way, because I don't get error from the chrome/firefox console and if I debug the script I can see the results. But after the end of the script the result disappears from the page.
Actually I've this situation:
DEBUGGING:
I see the alert and the text in the div, but they disappear after the end of the script
NOT DEBUGGING:
I can't see the result (why the alert don't stop the script??)
If change the script with this (i add just an alert)
<script type="text/javascript">
function CallService() {
Methodo_app.WebService1.HelloWorld("Yourself", onSuccess);
alert("hello")
}
function onSuccess(result) {
alert(result)
var outDiv = document.getElementById("outputDiv");
outDiv.textContent = result;
}
</script>
I can see the alert(result) and the text in the div but they still disappear after the end of the script.
I don't know if it's a problem of refresh or it's a sync problem
I've added an onFail
function and I see if I run the call to webservice will fail, but if I debug the call its on success
Solution
Well missng
return false;
to the function
function CallService() {
Methodo_app.WebService1.HelloWorld("Yourself", onSuccess);
}