Click here to Skip to main content
15,909,539 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai I am using the autocomplete box in query _ hear I am getting the data from webmethod in json data now jquery how to deserialize Jason object and bind the TextBox below is my code
C#
$(document).ready(function () {
            debugger;
            $(".autosuggest").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "Saleorder.aspx/GetAutoCompleteData",
                        data: "{'username':'" + document.getElementById('pagebody_txtSearch').value + "'}",
                        dataType: "json",
                        success: function (data) {
                            debugger
                            response(data.d);
                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                },
                select: function (event, ui) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "Saleorder.aspx/GetSelectedValue",
                        data: "{'username':'" + ui.item.value + "'}",
                        dataType: "json",
                        success: function (data) {
                            debugger
                            var obj = jQuery.parseJSON(data);
                            alert(obj);
                            //   the alert (obj) is null value . How to bind the value to text box                         
                            $("#<%=txtDeliveryDate.ClientID %>").val(data.d.ItemCode)
                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                }
            });
        });
Posted
Updated 3-Sep-13 20:29pm
v2
Comments
Jameel VM 4-Sep-13 2:20am    
try Json.Stringfy(data)

Not sure how jQuery does it but you use the eval function of javascript.

JavaScript
var jsonString = '{a: 1, b: 2}';
var jsonObject = eval('(' + jsonString + ')');


Simple!
 
Share this answer
 
Using eval() for this can be dangerous - you should use JSON.parse() if the browser supports it (and most do - see http://caniuse.com/json[^])

JavaScript
var object = JSON.parse('{"attr":"value"}');
 
Share this answer
 

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