Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
JavaScript
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);
            }
        }
    });
}
Posted
Updated 17-Apr-13 21:39pm
v2
Comments
Prasad Khandekar 18-Apr-13 3:44am    
Can you post the JSON response and the error? Does your JSON response contains an array named "d". What is UserDetails?

1 solution

The problem is data.d contains the data, but you are assigning data like below...
data[i].FName, which will not give you the FirstName.

As you are debugging the code, you can see that the value are in data.d.

So, you should read like data.d[i].FName, but you have to check whether it is working or not. You can use FireBug of Firefox and use the watch window to evaluate this code and check whether you are getting data or not.

And you have used
UserDetails.LName
UserDetails.Address
UserDetails.Email

which are not defined.

You should have used
data.d[i].LName
data.d[i].Address and
data.d[i].Email respectively.
 
Share this answer
 
Comments
AshishvermaMCA 18-Apr-13 4:52am    
thanks i m trying suggest by you.
Ok. And let me know what you found out.
AshishvermaMCA 18-Apr-13 5:12am    
i have chaged according to you but still issue remains same. data.d[i].FName having the records i saw the value by debuging it. When assign these values to textbox but values is not displaying in textbox. $("#<%=txtFname.ClientID%>").val(data.d[i].FName);
So, you are getting value in data.d[i].FName, right ?
Have you checked while debugging whether the textbox is accessed or not. I mean the code
$("#<%=txtFname.ClientID%>") selects the textbox or not...

And see if there are any errors in console window of FireBug.

Please check and also post all the html and jQuery code here. I will try to find out the problem at my end.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900