Ciao a tutti, ho il problema che non mi compare nulla a vide richiamando una <WebMethod()>, ho fatto vari tentativi con percorsi e dati diversi ed altre prove (da smanettone). Questo codice è copiato da un esempio ma anche questo non funziona. La pagina è aspx ed è sotto ad una masterpage
<script type="text/javascript">codice HTML:<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script> <div><br />sotto</div><div> <div>Your Name :<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><input id="btnGetTime" type="button" value="Show Current Time" onclick = "Hello" /></div><Button ID="cmdSave" title="CLICCAMI" onclick = "Hello()" class="btn"></Button></div> <div> <table> <tbody> <tr> <th> Value 1: </th> <td> <asp:TextBox ID="txtValue1" runat="server" /> </td> </tr> <tr> <th> Value 2: </th> <td> <asp:TextBox ID="txtValue2" runat="server" /> </td> </tr> </tbody></table></div> <asp:Button ID="btnGo" Text="Go" OnClientClick="CallService(); return false;" runat="server" /> <asp:Label ID="lblResult" Text=" " Width="100%" runat="server" /> <style> .loading{ background-image: url('ajax-loader.gif'); background-repeat: no-repeat;} </style>
function CallService() {
$.ajax({
type: "POST",
url: "http://localhost:4587/asmx/Add",
data: "{ 'value1': " + $("#txtValue1").val() + ", 'value2': " + $("#txtValue2").val() + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
}
function OnSuccess(data, status) {
$("#lblResult").html(data.d);
}
function OnError(request, status, error) {
$("#lblResult").html(request.statusText);
}
</script>
<script type="text/javascript">
function CallService() {
$("#lblResult").addClass("loading");
$.ajax({
type: "POST",
url: "http://localhost:4587/MS.asmx/HelloWorld",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: Success,
error: Error
});
}
function Success(data, status) {
$("#lblResult").removeClass("loading");
$("#lblResult").html(data.d);
}
function Error(request, status, error) {
$("#lblResult").removeClass("loading");
$("#lblResult").html(request.statusText);
}
</script>Grazie a tutticodice: