日期:2014-05-16  浏览次数:21461 次

新手求帮忙.
a.html
我用jquery 跳转到一个asp页面做数据返回.代码如下.
<script>
function Conn()
{
$.get("site.asp?t="+Math.random(),{"action":"get"},function(json)
{
alert(json.site.length);
});
}
</script>
<button id="btn" onclick="Conn();">create</button>

site.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<%
str="{"site":{"province"":"福建","city":"厦门"}}"  
response.write str  
%>  

报错 site.length 为空或不是对象.
我知道这有可能是返回的空值.但我真的不知道是为什么.

------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript" src="jquery-1.9.1.js"></script>
    <script type="text/javascript">
function Conn()
{
//alert("sss");
//$.get("site.asp?t="+Math.random(),
// {"action":"get"},
// function(json)
// {
// alert(json);
// });
$.ajax({
type: "get",
url: "site.asp?t="+Math.random(),
data:{action:"get"},
dataType: "json",
timeout:3000,
success: function (data) {
alert(data.site.province);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("操作超时,请重新再试");
}
});

}
</script>

 </head>

 <body>
<button id="btn" onclick="Conn();">create</button>
 </body>
</html>


<%
Response.charset="gbk"
str="{""site"":{""province"":""福建"",""city"":""厦门""}}"  
response.write str  
%>