default.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="demo_Default" %><!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 runat="server">
<title>demo</title>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$.getJSON(
"test.aspx",//产生JSON数据的服务端页面
//对返回的JSON数据进行处理,本例以列表的形式呈现
function(json){
//循环取json中的数据,并呈现在列表中
$.each(json,function(i){
$("#list").append("<li>name:"+json[i].name+" Age:"+json[i].age+"</li>")
})
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" />
<ul id="list"></ul>
</div>
</form>
</body>
</html>
test.aspx.cs protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
// string data = "[{name:\"fan\",age:26},{name:\"wang\",age:25}]";
string data = "[{name:\"ants\",age:24},{name:\"lele\",age:23}]";//构建的json数据
//下面两句是用来测试前台向此页面发出的查询字符
//string querystrname = context.Request.QueryString.GetValues("name")[0];//取查询字符串中namer的值
//string querystage = context.Request.QueryString.GetValues("age")[0];//取查询字符串中age的值
Response.Write(data);
}
}
这个我是网上找的。那里错了导致显示不出消息。初次接触jquery。。感谢
<head runat="server">
<title>demo</title>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$.getJSON(
"test.aspx",//产生JSON数据的服务端页面
//对返回的JSON数据进行处理,本例以列表的形式呈现
function(json){
//循环取json中的数据,并呈现在列表中
$.each(json,function(i){
$("#list").append("<li>name:"+json[i].name+" Age:"+json[i].age+"</li>")
})
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" />
<ul id="list"></ul>
</div>
</form>
</body>
</html>
test.aspx.cs protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
// string data = "[{name:\"fan\",age:26},{name:\"wang\",age:25}]";
string data = "[{name:\"ants\",age:24},{name:\"lele\",age:23}]";//构建的json数据
//下面两句是用来测试前台向此页面发出的查询字符
//string querystrname = context.Request.QueryString.GetValues("name")[0];//取查询字符串中namer的值
//string querystage = context.Request.QueryString.GetValues("age")[0];//取查询字符串中age的值
Response.Write(data);
}
}
这个我是网上找的。那里错了导致显示不出消息。初次接触jquery。。感谢
Response.Clear();
Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
// string data = "[{name:\"fan\",age:26},{name:\"wang\",age:25}]";
string data = "[{name:\"ants\",age:24},{name:\"lele\",age:23}]";//构建的json数据
//下面两句是用来测试前台向此页面发出的查询字符
//string querystrname = context.Request.QueryString.GetValues("name")[0];//取查询字符串中namer的值
//string querystage = context.Request.QueryString.GetValues("age")[0];//取查询字符串中age的值
Response.Write(data);
Response.End();
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function() {
$('#btn').click(function() {
$.getJSON(
"test.aspx", //产生JSON数据的服务端页面
//对返回的JSON数据进行处理,本例以列表的形式呈现
function(json) {
//循环取json中的数据,并呈现在列表中
$.each(json, function(i) {
$("#list").append("<li>name:" + json[i].name + " Age:" + json[i].age + "</li>")
})
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" id="btn" value="ajax" />
<ul id="list"></ul> </form>
</body>
</html>test.aspx.csprotected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
// string data = "[{name:\"fan\",age:26},{name:\"wang\",age:25}]";
string data = "[{name:\"ants\",age:24},{name:\"lele\",age:23}]";//构建的json数据
//下面两句是用来测试前台向此页面发出的查询字符
//string querystrname = context.Request.QueryString.GetValues("name")[0];//取查询字符串中namer的值
//string querystage = context.Request.QueryString.GetValues("age")[0];//取查询字符串中age的值
Response.Write(data);
Response.End();
}
最开始确实是没end();