Ciao, ecco l'esempio, prima di quanto pensassi.
Nella pagina aspx
codice:
<%@ Page Language="VB" AutoEventWireup="true"%> <%@ Import Namespace="System.Web.Services" %> <%@ Import Namespace="System.Web.Script.Services" %> <script runat ="server" > </script> <!DOCTYPE html> <html> <head> <title>Calling page methods with jQuery</title> <style type="text/css"> #Result { cursor: pointer; } </style> </head> <body> <form runat ="server" > <ajaxtoolkit:ToolkitScriptManager runat="Server" ID="scriptManager" EnablePageMethods="true" EnableScriptGlobalization="true" ></ajaxtoolkit:ToolkitScriptManager> <div id="Result">Click here for the time.</div> <script type="text/javascript" src="Script/jquery-1.7.1.min.js"></script> <script type ="text/javascript"> $('#Result').click(function () { alert("in function"); $.ajax({ type: 'POST', url: '/WebService.asmx/HelloWorld', data: '{ArgumentName:"ArgumentValue"}', contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (msg) { alert(msg.d); // d è il risultato della funzione //alert("funzionato"); } }); }); </script> </form> </body> </html>
Mentre nel file WebService.asmx
codice:
<%@ WebService Language="VB" Class="WebService" %> Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols ' Per consentire la chiamata di questo servizio Web dallo script utilizzando ASP.NET AJAX, rimuovere il commento dalla riga seguente. <System.Web.Script.Services.ScriptService()> _ <WebService(Namespace:="http://tempuri.org/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ Public Class WebService Inherits System.Web.Services.WebService <WebMethod()> _ Public Function HelloWorld() As String Return "Hello World" End Function End Class
Scusa, ho visto che non mi ha formattato correttamente, ma sto proprio di corsa...
Fammi sapere, c'era anche qualche impostazione nel web.config ma non ricordo quale parte fosse.
Il link principale che avevo purtroppo mi è andato perso.
Qui c'è un altro utile esempio che ho provato e che mi ha funzionato.
http://www.blackbeltcoder.com/Articl...ols-using-ajax
Ciao