Я пытаюсь вызвать веб-метод на странице aspx, используя jquery ajax. Код ajax вызывает страницу, но я не могу перейти к методу, хотя Page_Load был получен после запроса ajax Post. Я пробовал разными способами, но не могу.
Я надеюсь, что вы можете мне помочь, я схожу с ума.
protected void Page_Load(object sender, EventArgs e)
{
string nombre = Request.QueryString["nombre"];
if (!IsPostBack)
{
this.CargarDatosIniciales();
}
}
[WebMethod(enableSession:true)]
[ScriptMethod()]
public static void GuardarDatosFamilia(string nombre, string tipoDoc)
{
string nombrePersona = nombre;
string tipoDocumento = tipoDoc;
}
$.ajax({
type: "POST",
url: "FRM_Caracterizacion.aspx/GuardarDatosFamilia", //Direccion del servicio web segido de /Nombre del metodo a llamar
beforeSend: function () { alert('I am sending'); },
data: "{'nombre':'"+ nombre+"','tipoDoc':'"+ tipoDoc"'}",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
ОБНОВИТЬ:
Вот что я получаю в Firebug:
POST http://localhost:51620/FRM_Caracterizacion.aspx/GuardarDatosFamilia 200 OK 3.22s
Parámetros application/x-www-form-urlencoded
nombre Jhon Fredy
tipoDoc 1
Fuente
nombre=Jhon+Fredy&tipoDoc=1
ОБНОВЛЕНИЕ 2:
РЕШЕНИЕ
Что я сделал для моей конкретной проблемы:
$.ajax({
type: "POST",
url: "FRM_Caracterizacion.aspx", //Direccion del servicio web segido de /Nombre del metodo a llamar
beforeSend: function () { alert('I am sending'); },
data: { metodo: 'AgregarDatosFamilia',
nombre:nombre,
tipoDoc:tipoDoc
},
dataType: "json" //Esto quiere decir que los datos nos llegaran como un objeto json
});
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Form["metodo"] == "AgregarDatosFamilia")
{
this.GuardarDatosFamilia();
}
this.CargarDatosIniciales();
}
}
public void GuardarDatosFamilia()
{
string nombre = Request.Form["nombre"].ToString(),
string tipoDoc = Request.Form["tipoDoc"].ToString()
}
Спасибо всем, я ценю предложения!