Saludos...
Hace ratito que intento realizar una llamada a un método desde una página asp. Actualmente uso jquery para la llamada. al compilarlo todo bien, pero a la hora de ejecutarlo, ingreso mi nombre y presiono el botón y no pasa nada. He revisado y nose por donde puede estar la falla.
El proyecto esta en Asp net web en C#, framework 2.0 y Visual Studio 2005.
Aquí el código:
Holaconjquery.aspx
Código:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Web Service Sample Page</title>
<script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#sayHelloButton").click(function(event){
$.ajax({
type: "POST",
url: "service_hello.asmx/HelloToYou",
data: "{'name': '" + $('#name').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h1> Web Services with jQuery </h1>
Enter your name:
<input id="name" />
<br />
<input id="sayHelloButton" value="Say Hello"
type="button" />
</form>
</body>
</html>
service_hello.asmx.cs
Código:
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Script.Services;
namespace jquery_aspnet_oficial
{
/// <summary>
/// Descripción breve de
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class service_hello : System.Web.Services.WebService
{
[WebMethod()]
public static string GetDate()
{
return DateTime.Now.ToString();
}
[WebMethod()]
public string sayHello()
{
return "hello ";
}
[WebMethod()]
public static string HelloToYou(string name)
{
return "Hello " + name;
}
}
}
Una manito es muy bienvenida