jquery如何反序列化json数据 [英] jquery how to deserialize json data

查看:89
本文介绍了jquery如何反序列化json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai我在查询中使用自动完成框_听到我从json数据中获取webmethod的数据现在jquery如何反序列化Jason对象并绑定下面的TextBox是我的代码

 $(document ).ready(function(){
debugger;
$( 。autosuggest)。autocomplete({
source:function(request,response){
$ .ajax({
type: POST
contentType: application / json; charset = utf-8
url: Saleorder.aspx / GetAutoCompleteData
数据: {'username':' +文档。 getElementByI d(' pagebody_txtSearch')。 value + '}
dataType: json
success:function(data){
debugger
response(data.d);
},
错误:函数(结果){
alert( 错误 );
}
});
},
选择:function( event ,ui){
$ .ajax({
类型: POST
contentType: application / json; charset = utf-8
url: Saleorder.aspx / GetSelectedValue
data: {'username':' + ui.item。 value + '}
dataType: < span class =code-string> json

success:function(data){
debugger
var obj = jQuery.parseJSON(data);
alert(obj);
// alert(obj)为空值。如何将值绑定到文本框
$( #<%= txtDeliveryDate。 ClientID%>)。val(data.d.ItemCode)
},
错误:函数(结果){
alert( 错误);
}
});
}
});
});

解决方案

(document).ready(function(){
debugger;

。autosuggest)。autocomplete({
source:function(request,response){


.ajax({
type: POST
contentType: application / json; charset = utf -8
url: Saleorder.aspx / GetAutoCompleteData
数据: {'username':' + document.getElementById(' pagebody_txtSearch')。 + '}
dataType: json
成功:函数(数据){
debugger
响应(data.d);
},
错误:函数(结果){
alert( 错误 );
}
});
},
选择:function( event ,ui){

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

$(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");
                        }
                    });
                }
            });
        });

解决方案

(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) {


这篇关于jquery如何反序列化json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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