前台
<script type="text/javascript">
var v_username="";
$(document).ready(function(){
$.ajax({
url: "/qzone_huifu.ashx",
type:"GET",
cache:false,
datetype:"json",
success:function(result){
alert(result);
$("#lblcount")(result.cont1);
$("#Visitor")(result.cont2);
}
})
});
</script>
后台
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/x-json";
context.Response.CacheControl = "no-cache";
string a = "{\"cont1\":1111,\"cont2\":2222}";
context.Response.Write(a);
}
}
一直取不到值啊啊alert(result); 这个有值
但是
result.cont1这个就是空了 求大侠指点迷津
------解决方案--------------------------------------------------------
eval('"+result+"');
alert(result.cont1);
alert()前面加上eval(),將返回的結果指定為json
------解决方案--------------------------------------------------------
Result += "{\"people\":[";
if (_Datas.Count() > 0)
{
foreach (var _Data in _Datas)
{
Result += "{\"id\":\"" + _Data.CSTC_ID + "\",\"mc\":\"" + _Data.CSTC_MC + "\"}";
Result += ",";
}
Result = Result.Substring(0, Result.Length - 1);
}
Result += "]}";
json格式数据