如何将Json类型对象的返回值分配给TextBox但我收到错误 [英] How to assign return value from Json type object into TextBox but i am getting error

查看:59
本文介绍了如何将Json类型对象的返回值分配给TextBox但我收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ajax调用jquery函数它将返回基于指定id的FName,Lname,Address,Email。当我要将这些值分配给TextBox,获取错误时,它返回json类型对象。所以请帮助我。

  function  BindGridView(id){
调试器;
var params = {ID:' + id + '};
$ .ajax({
type: POST
url: InsertoninGridViewusingJQuery.aspx / GetRecords
data:params,
contentType: application / json
dataType: JSON
成功: function (data){
alert(data.d.length);
for var i = 0 ; i< data.d.length; i ++){
debugger ;
$( #<%= txtFname.ClientID%>)。val(数据[i] .FName);
$( #<%= txtLname.ClientID%>)。val(UserDetails.LName);
$( #<%= txtAddress.ClientID%>)。val (UserDetails.Address);
$( #<%= txtEmail.ClientID%>)。val (UserDetails.Email);
}
}
});
}

解决方案

.ajax({
type: POST
url: InsertoninGridViewusingJQuery.aspx / GetRecords
data:params,
contentType: application / json
dataType: JSON
成功: function (data){
alert(data.d.length);
for var i = 0 ; i< data.d.length; i ++ ){
调试器;


< span class =code-string>#<%= txtFname.ClientID%>)。val(data [i] .FName);


#<%= txtLname.ClientID%>中)VAL(UserDetails.LName);

i am calling a jquery function with ajax it will returned the FName,Lname,Address,Email on basic of specified id. It returns the json type object when i am going to assign these values to TextBox ,Getting error. so please help me.

function BindGridView(id) {
    debugger;
    var params = "{ID:'" + id + "'}";
    $.ajax({
        type: "POST",
        url: "InsertoninGridViewusingJQuery.aspx/GetRecords",
        data: params,
        contentType: "application/json",
        dataType: "JSON",
        success: function (data) {
            alert(data.d.length);
            for (var i = 0; i < data.d.length; i++) {
                debugger;
                $("#<%=txtFname.ClientID%>").val(data[i].FName);
                $("#<%=txtLname.ClientID%>").val(UserDetails.LName);
                $("#<%=txtAddress.ClientID%>").val(UserDetails.Address);
                $("#<%=txtEmail.ClientID%>").val(UserDetails.Email);
            }
        }
    });
}

解决方案

.ajax({ type: "POST", url: "InsertoninGridViewusingJQuery.aspx/GetRecords", data: params, contentType: "application/json", dataType: "JSON", success: function (data) { alert(data.d.length); for (var i = 0; i < data.d.length; i++) { debugger;


("#<%=txtFname.ClientID%>").val(data[i].FName);


("#<%=txtLname.ClientID%>").val(UserDetails.LName);


这篇关于如何将Json类型对象的返回值分配给TextBox但我收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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