對Jquery中的ajax再封裝,簡化操作示例
<!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>
<title>jQueryAjaxJson取值示例</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); //數(shù)組
$.each(json, function (index, item) {
//循環(huán)獲取數(shù)據(jù)
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提交
* @param url
* @param param
* @param datat 為html,json,text
* @param callback回調(diào)函數(shù)
* @return
*/
function jsonAjax(url, param, datat, callback) {
$.ajax({
type: "post",
url: url,
data: param,
dataType: datat,
success: callback,
error: function () {
jQuery.fn.mBox({
message: '恢復(fù)失敗'
});
}
});
}
</script>
</head>
<body>
<span id="ccc"></span>
<span id="ddd"></span>
</body>
</html>
using System;
//新增
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)
{
//數(shù)據(jù)模擬,僅供參考
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符合條件" : "sorry不符合條件";
}
else if (gettype == "json")
{
List<Student> list = new List<Student>();
for (int i = 0; i < 50; i++)
{
Student a = new Student();
a.Name = "張三" + i;
a.Age = i;
a.Sex = "男";
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;
}
}
相關(guān)文章
JQuery實現(xiàn)鼠標(biāo)移動圖片顯示描述層的方法
這篇文章主要介紹了JQuery實現(xiàn)鼠標(biāo)移動圖片顯示描述層的方法,涉及jQuery鼠標(biāo)事件及動畫效果的使用技巧,需要的朋友可以參考下2015-06-06jQuery Form 表單提交插件之formSerialize,fieldSerialize,fieldValue,r
這篇文章主要介紹了jQuery Form 表單提交插件之formSerialize,fieldSerialize,fieldValue,resetForm,clearForm,clearFields的應(yīng)用的相關(guān)資料,需要的朋友可以參考下2016-01-01jQuery1.3.2 升級到j(luò)Query1.4.4需要修改的地方
jQuery1.3.2 升級到 1.4.4 ,需要修改的地方,需要的朋友可以參考下。2011-01-01jquery PrintArea 實現(xiàn)票據(jù)的套打功能(代碼)
下面小編就為大家?guī)硪黄猨query PrintArea 實現(xiàn)票據(jù)的套打功能(代碼)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03