在jQuery AJAX执行和回发之后,Mantain控制状态 [英] Mantain control state after a jQuery AJAX execution and a postback

查看:115
本文介绍了在jQuery AJAX执行和回发之后,Mantain控制状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是事情,我有以下jQuery ajax调用,我在其中添加一个表:



$ .ajax({

类型:POST,

url:datosParcelas.aspx / AgregarOrigen,

数据:{'cuenta':'+ nroCta +' },

contentType:application / json; utf-8,

dataType:json,

成功:函数(响应) ){

if(response.d)

if($('#tblCuentas> tbody> tr')。length == 1)

$(#tblCuentas)。css('display','');



$(#tblCuentas> tbody> tr:last )。after(response.d);



$('#cp_lblError')。html('');

$( #txtCuenta)。val('');

$(#txtCuenta)。focus();



}

else {

$('#cp_lblError')。html('');

}

$(。loading)。hide();

$ btn.button('reset');

},

错误:函数(错误){

showAlertModal(错误,错误);

$(。loading)。hide();

$ btn.button('reset');

}

});



我使用webMethod返回:



 [WebMethod(EnableSession = true)] 
公共静态字符串AgregarOrigen(string cuenta)
{
string html = null;
try
{
// cuenta = cuenta.Trim()。Replace( - ,)。Replace(/,);
if(HttpContext.Current.Session [idTramite] == null)
返回ERROR:SESION;

if(string.IsNullOrEmpty(cuenta))
returnERROR:Ingrese la cuenta;

使用(TDService ws = new TDService())
{
DatosUbicacion [] datosFront = ws.TramiteLoadDatosUbicacion(0,0,cuenta);
if(datosFront!= null&& datosFront.Length> 0)
{
if(ws.TD_Cuenta_Save((int)HttpContext.Current.Session [idTramite], datosFront [0] .IdCuenta))
{
cuentas.Add(datosFront [0] .IdCuenta);

html =< tr > +
< td > + datosFront [0] .TipoParcela +< / td > +
< td > + datosFront [0] .CuentaDescriptor +< / td > +
< ; td > + datosFront [0] .ParcelaDescriptor +< / td > +
< td > + datosFront [0] .EstadoParcela +< / td > +
< td > + datosFront [0] .Departamento +< / td > +
< td > + datosFront [0] .Pedania +< / td > +
< td > < a class =' elimina' title =' Eliminar' onclick =' fn_eliminarCuentaClick(this)' > < img src =' images / delete.png' / > < / a > < p class =' hidden' > + datosFront [0] .IdCuenta +< p > < / td > +
< ; / tr > ;

HttpContext.Current.Session [origenes] = cuentas;
}
其他
返回ERROR:No se pudo insertar el Titular.Intente mas tarde。;

}
其他
返回ERROR:La Cuenta ingresada no existe;
}
}
catch(Exception ex)
{
LogError.Write(ex);
返回ERROR:错误inesperado。没有se pudo asociar la Cuenta al tramite+(int)HttpContext.Current.Session [idTramite] +。Intente mas tarde。;
}
返回html;
}







我遇到的问题是,当我在回复时页面,通过ajax添加的行,从de table中删除。我究竟做错了什么??我将不胜感激!

解决方案

.ajax({

类型:POST,

url :datosParcelas.aspx / AgregarOrigen,

数据:{'cuenta':'+ nroCta +'},

contentType:application / json; utf-8,

dataType:json,

成功:函数(响应){

if(response.d)

if(


('#tblCuentas> tbody> tr')。length == 1)


< blockquote>(#tblCuentas)。css('display','');



Here is the thing, I have the following jQuery ajax call, where I add a to a table:

$.ajax({
type: "POST",
url: "datosParcelas.aspx/AgregarOrigen",
data: "{'cuenta' : '" + nroCta + "'}",
contentType: "application/json; utf-8",
dataType: "json",
success: function (response) {
if (response.d)
if ($('#tblCuentas > tbody > tr').length == 1)
$("#tblCuentas").css('display', '');

$("#tblCuentas > tbody > tr:last").after(response.d);

$('#cp_lblError').html('');
$("#txtCuenta").val('');
$("#txtCuenta").focus();

}
else {
$('#cp_lblError').html('');
}
$(".loading").hide();
$btn.button('reset');
},
error: function (error) {
showAlertModal("Error",error);
$(".loading").hide();
$btn.button('reset');
}
});

I return the with the webMethod:

[WebMethod(EnableSession = true)]
        public static string AgregarOrigen(string cuenta)
        {
            string html = null;
            try
            {
                //cuenta = cuenta.Trim().Replace("-", "").Replace("/","");
                if (HttpContext.Current.Session["idTramite"] == null)
                    return "ERROR:SESION";

                if (string.IsNullOrEmpty(cuenta))
                    return "ERROR:Ingrese la cuenta";

                using (TDService ws = new TDService())
                {
                    DatosUbicacion[] datosFront = ws.TramiteLoadDatosUbicacion(0, 0, cuenta);
                    if (datosFront != null && datosFront.Length > 0)
                    {
                        if (ws.TD_Cuenta_Save((int)HttpContext.Current.Session["idTramite"], datosFront[0].IdCuenta))
                        {
                            cuentas.Add(datosFront[0].IdCuenta);

                            html = "<tr>" +
                                "<td>" + datosFront[0].TipoParcela + "</td>" +
                                "<td>" + datosFront[0].CuentaDescriptor + "</td>" +
                                "<td>" + datosFront[0].ParcelaDescriptor + "</td>" +
                                "<td>" + datosFront[0].EstadoParcela + "</td>" +
                                "<td>" + datosFront[0].Departamento + "</td>" +
                                "<td>" + datosFront[0].Pedania + "</td>" +
                                "<td><a class='elimina' title='Eliminar' onclick='fn_eliminarCuentaClick(this)'><img src='images/delete.png' /></a> <p class='hidden'>" + datosFront[0].IdCuenta + "<p></td>" +
                                "</tr>";

                            HttpContext.Current.Session["origenes"] = cuentas;
                        }
                        else
                            return "ERROR: No se pudo insertar el Titular. Intente mas tarde.";

                    }
                    else
                        return "ERROR:La Cuenta ingresada no existe";
                }
            }
            catch (Exception ex)
            {
                LogError.Write(ex);
                return "ERROR: Error inesperado. No se pudo asociar la Cuenta al tramite " + (int)HttpContext.Current.Session["idTramite"] + ". Intente mas tarde.";
            }
            return html;
        }




The problem I have, is that when I do a postback on the page, the rows added through ajax, deletes from de table. What am I doing wrong?? I will appreciate any help!

解决方案

.ajax({
type: "POST",
url: "datosParcelas.aspx/AgregarOrigen",
data: "{'cuenta' : '" + nroCta + "'}",
contentType: "application/json; utf-8",
dataType: "json",
success: function (response) {
if (response.d)
if (


('#tblCuentas > tbody > tr').length == 1)


("#tblCuentas").css('display', '');


这篇关于在jQuery AJAX执行和回发之后,Mantain控制状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆