28,409
社区成员




<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<%
username="tom"
sex="男"
age="18"
response.write "姓名:"+username +"<br/>"+"性别:"+sex +"<br/>"+"年龄:"+age
%>
</body>
</html>
$(function (){
$.ajax({
url:"json.asp",
dataType:'json',
async:true,
type:'get',
success:function(data){
alert(data.a);
},
error:function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}});
})
json.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.Charset = "UTF-8" %>
<%
username="tom"
sex="男"
age="18"
'response.write "姓名:"+username +"<br/>"+"性别:"+sex +"<br/>"+"年龄:"+age
response.write "{""a"":" & username & ",""b"":" & sex & ",""c"":" & age & "}"
%>
[/quote]
dataType:'json'时需要设置输出类型,如果不设置得到字符串后再解析也可以
$(function (){
$.ajax({
url:"json.asp",
dataType:'json',
async:true,
type:'get',
success:function(data){
alert(data.a);
},
error:function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}});
})
json.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.Charset = "UTF-8" %>
<%
username="tom"
sex="男"
age="18"
'response.write "姓名:"+username +"<br/>"+"性别:"+sex +"<br/>"+"年龄:"+age
response.write "{""a"":" & username & ",""b"":" & sex & ",""c"":" & age & "}"
%>