Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>jqueryajaxjson Sample </title>
<script type= "Text/javascript" src= "Scripts/jquery-1.4.4.min.js" ></script>
<script type= "Text/javascript" >
$ (function () {
Jsonajax ("ajaxquery.aspx", "Type=json", "JSON", CallBack);
Jsonajax ("ajaxquery.aspx", "Id=1&name=2&type=text", "text", callbacktxt);
});
function CallBack (data) {
$ ("#ddd"). html (');
var json = eval (data); Array
$.each (JSON, function (index, item) {
Looping through data retrieval
var name = Json[index]. Name;
var age = Json[index]. Age;
var sex = Json[index]. Sex;
$ ("#ddd"). HTML ($ ("#ddd"). HTML () + "<br>" + name + "+ Age +" "+ Sex +" <br/> ");
});
};
function Callbacktxt (data) {
$ ("#ccc"). HTML (data);
};
/**
* Ajax Post Submission
* @param URL
* @param param
* @param datat for Html,json,text
* @param callback callback function
* @return
*/
function jsonajax (URL, param, Datat, callback) {
$.ajax ({
Type: "Post",
Url:url,
Data:param,
Datatype:datat,
Success:callback,
Error:function () {
JQuery.fn.mBox ({
Message: ' Restore failed '
});
}
});
}
</script>
<body>
<span id= "CCC" ></span>
<span id= "DDD" ></span>
</body>
Copy Code code as follows:
Using System;
New
Using System.Web.Script.Serialization;
Using System.Collections.Generic;
public partial class AjaxQuery:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Data simulation, for reference only
String messgage = String. Empty;
String id = request["id"];
String name = request["Name"];
String gettype = request["type"];
if (gettype== "text")
{
Messgage = (id = = "1" && name = = "2")? "OK meets the condition": "Sorry not meet the condition";
}
else if (GetType = "JSON")
{
list<student> list = new list<student> ();
for (int i = 0; i < i++)
{
Student a = new Student ();
A.name = "John" + I;
A.age = i;
A.sex = "male";
List. Add (a);
}
Messgage = new JavaScriptSerializer (). Serialize (list);
}
Else
{ }
Response.Write (Messgage);
Response.End ();
}
}
public struct Student
{
public string Name;
public int age;
public string Sex;
}
}