首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

上拉列表绑定选种有关问题

2013-02-24 
下拉列表绑定选种问题本帖最后由 showbo 于 2012-12-29 11:45:00 编辑数据库读取数据后,通过AJAX 传到前台

下拉列表绑定选种问题
本帖最后由 showbo 于 2012-12-29 11:45:00 编辑 数据库读取数据后,通过AJAX 传到前台JS,下列表框绑定选种项,有时候绑定不到,不知道什么情况,代码如下

 var option = {
            type: "post",
            url: "../xxx/xxx.aspx/selectbytid",
            data: "{'tid':'" + cid + "'}",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (response) {

                var o = jQuery.parseJSON(response.d);
                if (o != null) {
                    $("#type").attr("Value", o.TypeId);

                    $("#ptype").show();
                    var option = { type: "post",
                        url: "../xx/xxx.aspx/SelectType",
                        data: "{'pid':'" + o.TypeId + "'}",
                        contentType: "application/json;charset=utf-8",
                        dataType: "JSON",
                        success: function (response) {
                            var n = eval(response);
                            $("#ptype").append(n.d); //这里绑定选种项
                            $("#ptype").attr("Value", o.ptype);//这里绑定选种项
                        }
                    }
                    $.ajax(option);

有时候绑定不到选种项,不知道什么问题高手帮忙.
[解决办法]
动态页有问题吧。。

                    var option = { type: "post", 


                        url: "../xx/xxx.aspx/SelectType",
                        data: "{'pid':'" + o.TypeId + "'}",
                        contentType: "application/json;charset=utf-8",
                        dataType: "JSON",
/////////////////////////////////
                        error: function(xhr){alert('发生错误\n'+xhr.responseText)},
/////////////////////////////////
                        success: function (response) {
                            var n = eval(response);
                            $("#ptype").append(n.d); //这里绑定选种项
                            $("#ptype").attr("Value", o.ptype);//这里绑定选种项
                        }
                    }

热点排行