关于服务器端返回json数据问题

时间:2021-12-06 09:44:13
function getAjaxList(explorer, pageno) {
$
.post(
"Community_Dictionary.asp",
null,
function(json) {
var jsonLength = json.list.length;
var dictionaryData = "";
if (jsonLength > 0) {
dictionaryData = "<div style='margin-bottom:10px;background-color:#d6efac;line-height:28px;padding-left:20px;'><img src='/house/img/xz_tb.gif'/><font color=green><b>选择小区</b></font>(如下列表中不存在,点此<a id='create-new-floor' href='javascript:void(0)'><font color=red>+新建小区</font></a>)</div>";
for ( var i = 0; i < json.list.length; i++) {
var Community_ID = json.list[i].Community_ID;
var Community = json.list[i].Community;
var Address = json.list[i].Address;
if (Address == "null")
Address = "";
var Area_ID = json.list[i].Area_ID;
dictionaryData = dictionaryData
+ "<div style='height:22px;line-height:29px;padding-left:40px;overflow:hidden;'><img src='/house/img/sjy_x.gif'/><a  class='item' href=\"javascript:;\" onClick=\"javascript:selectFloor("
+ "'" + Community_ID + "'," + "'" + Community
+ "','" + Address + "','" + Area_ID + "');\"><font color=#ff6200>"
+ Community + "</font></a><font color=#565e53> " + Address
+ "</font></div>";
}
//dictionaryData += "<a id='create-new-floor' href='javascript:void(0)'>列表中不存在,<span style='color:red;font-size:16px;'>点此</span>新建小区</a>";
} else {
dictionaryData += "<a id='create-new-floor' href='javascript:void(0)'>列表中不存在,<span style='color:red;font-size:16px;'>点此</span>新建小区</a>";
}
$("#dictionary").html(dictionaryData);
$("#create-new-floor").click(onCreateNewFloor_Click);
}, "json");
}



这是客户端 js代码


Response.Write "{ ""list"": [{ ""Community_ID"": ""1"", ""Community"":""天才"", ""Address"": ""我晕晕"" ,""Area_ID"":""15""}]}"

这是服务器端代码

为什么客户端接收不到 服务器返回的结果

10 个解决方案

#1


你先测试下
<form action="Community_Dictionary.asp" method=post><input type=submit></form>看看数据是否真的返回了

#2


测试过了 可以输出

{ "list": [{ "Community_ID": "1", "Community":"天才", "Address": "我晕晕" ,"Area_ID":"15"}]}
的啊



#3


那就是你使用方法不对,或者你选择的框架解析有问题

#4


我做了测试了啊

返回text 能返回字符串的 而且这个 json的格式也没错的啊

会不会是jquery的版本问题
我的是
最新的

jquery-1.4.2.js

#5


可以得到的。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
getAjaxList(0,0)
function getAjaxList(explorer, pageno) {
    $.post(
                    "Community_Dictionary.asp",
                    null,
                    function(json) {
                    
                        var jsonLength = json.list.length;
                     
                        var dictionaryData = "";
                        if (jsonLength > 0) {
                            dictionaryData = "<div style='margin-bottom:10px;background-color:#d6efac;line-height:28px;padding-left:20px;'><img src='/house/img/xz_tb.gif'/><font color=green><b>选择小区</b></font>(如下列表中不存在,点此<a id='create-new-floor' href='javascript:void(0)'><font color=red>+新建小区</font></a>)</div>";
                            for ( var i = 0; i < json.list.length; i++) {
                                var Community_ID = json.list[i].Community_ID;
                                var Community = json.list[i].Community;
                                
                                var Address = json.list[i].Address;
                                if (Address == "null")
                                    Address = "";
                                var Area_ID = json.list[i].Area_ID;
                                alert(Area_ID)
                                dictionaryData = dictionaryData
                                        + "<div style='height:22px;line-height:29px;padding-left:40px;overflow:hidden;'><img src='/house/img/sjy_x.gif'/><a  class='item' href=\"javascript:;\" onClick=\"javascript:selectFloor("
                                        + "'" + Community_ID + "'," + "'" + Community
                                        + "','" + Address + "','" + Area_ID + "');\"><font color=#ff6200>"
                                        + Community + "</font></a><font color=#565e53> " + Address
                                        + "</font></div>";
                            }
                            //dictionaryData += "<a id='create-new-floor' href='javascript:void(0)'>列表中不存在,<span style='color:red;font-size:16px;'>点此</span>新建小区</a>";
                        } else {
                            dictionaryData += "<a id='create-new-floor' href='javascript:void(0)'>列表中不存在,<span style='color:red;font-size:16px;'>点此</span>新建小区</a>";
                        }
                        $("#dictionary").html(dictionaryData);
                        $("#create-new-floor").click(onCreateNewFloor_Click);
                    }, "json");
}

</script>

#6


会不会是服务器端代码有错误啊

我服务器端就这么一句

<%
Response.Write "{""list"":[{""Community_ID"":""1"",""Community"":""天才"",""Address"":""我晕晕"",""Area_ID"":""15""}]};"
%>

#7


都已经给你贴出来了,你试验了吗?

#8


试了好多遍了  

{list:[{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15},{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15},{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15},{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15},{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15}]}

经理asp json类处理  返回这个样子的  也还是不行   只能返回字符类型 再 转换成 json对象来使用 不能直接返回 json类型

#9


我晕死 忙了半天是 编码问题

用  gb2312不行

在utf-8下面却行的 

#10


http://www.diysys.com有很多关于php,mysql,js,css的信息,适合新手和进阶者

#1


你先测试下
<form action="Community_Dictionary.asp" method=post><input type=submit></form>看看数据是否真的返回了

#2


测试过了 可以输出

{ "list": [{ "Community_ID": "1", "Community":"天才", "Address": "我晕晕" ,"Area_ID":"15"}]}
的啊



#3


那就是你使用方法不对,或者你选择的框架解析有问题

#4


我做了测试了啊

返回text 能返回字符串的 而且这个 json的格式也没错的啊

会不会是jquery的版本问题
我的是
最新的

jquery-1.4.2.js

#5


可以得到的。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
getAjaxList(0,0)
function getAjaxList(explorer, pageno) {
    $.post(
                    "Community_Dictionary.asp",
                    null,
                    function(json) {
                    
                        var jsonLength = json.list.length;
                     
                        var dictionaryData = "";
                        if (jsonLength > 0) {
                            dictionaryData = "<div style='margin-bottom:10px;background-color:#d6efac;line-height:28px;padding-left:20px;'><img src='/house/img/xz_tb.gif'/><font color=green><b>选择小区</b></font>(如下列表中不存在,点此<a id='create-new-floor' href='javascript:void(0)'><font color=red>+新建小区</font></a>)</div>";
                            for ( var i = 0; i < json.list.length; i++) {
                                var Community_ID = json.list[i].Community_ID;
                                var Community = json.list[i].Community;
                                
                                var Address = json.list[i].Address;
                                if (Address == "null")
                                    Address = "";
                                var Area_ID = json.list[i].Area_ID;
                                alert(Area_ID)
                                dictionaryData = dictionaryData
                                        + "<div style='height:22px;line-height:29px;padding-left:40px;overflow:hidden;'><img src='/house/img/sjy_x.gif'/><a  class='item' href=\"javascript:;\" onClick=\"javascript:selectFloor("
                                        + "'" + Community_ID + "'," + "'" + Community
                                        + "','" + Address + "','" + Area_ID + "');\"><font color=#ff6200>"
                                        + Community + "</font></a><font color=#565e53> " + Address
                                        + "</font></div>";
                            }
                            //dictionaryData += "<a id='create-new-floor' href='javascript:void(0)'>列表中不存在,<span style='color:red;font-size:16px;'>点此</span>新建小区</a>";
                        } else {
                            dictionaryData += "<a id='create-new-floor' href='javascript:void(0)'>列表中不存在,<span style='color:red;font-size:16px;'>点此</span>新建小区</a>";
                        }
                        $("#dictionary").html(dictionaryData);
                        $("#create-new-floor").click(onCreateNewFloor_Click);
                    }, "json");
}

</script>

#6


会不会是服务器端代码有错误啊

我服务器端就这么一句

<%
Response.Write "{""list"":[{""Community_ID"":""1"",""Community"":""天才"",""Address"":""我晕晕"",""Area_ID"":""15""}]};"
%>

#7


都已经给你贴出来了,你试验了吗?

#8


试了好多遍了  

{list:[{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15},{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15},{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15},{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15},{"Community_ID":21,"Community":"\u767D\u9A6C\u516C\u5BD3","Address":"\u6052\u9F99\u5E7F\u573A\u65C1\u8FB9","Area_ID":15}]}

经理asp json类处理  返回这个样子的  也还是不行   只能返回字符类型 再 转换成 json对象来使用 不能直接返回 json类型

#9


我晕死 忙了半天是 编码问题

用  gb2312不行

在utf-8下面却行的 

#10


http://www.diysys.com有很多关于php,mysql,js,css的信息,适合新手和进阶者

相关文章