<script type="text/javascript">
$(function()
{
$("#btnAjaxGet").click(function(event)
{
//發送Get請求
$("#divResult").load("../data/AjaxGetMethod.aspx?param=btnAjaxGet_click" + "×tamp=" + (new Date()).getTime());
});
$("#btnAjaxPost").click(function(event)
{
//發送Post請求
$("#divResult").load("../data/AjaxGetMethod.aspx", { "param": "btnAjaxPost_click" });
});
$("#btnAjaxCallBack").click(function(event)
{
//發送Post請求, 返回後執行回呼函數.
$("#divResult").load("../data/AjaxGetMethod.aspx", { "param": "btnAjaxCallBack_click" }, function(responseText, textStatus, XMLHttpRequest)
{
responseText = " Add in the CallBack Function! <br/>" + responseText
$("#divResult").html(responseText); //或者: $(this).html(responseText);
});
});
$("#btnAjaxFiltHtml").click(function(event)
{
//發送Get請求, 從結果中過濾掉 "鞍山" 這一項
$("#divResult").load("../data/AjaxGetCityInfo.aspx?resultType=html" + "×tamp=" + (new Date()).getTime() + " ul>li:not(:contains('鞍山'))");
});
})
</script>
------------------------------------
$("#Button1").click(function() {
$("#divResult").load($("#divResult").load("/Demo/AjaxGetMethod.aspx", { "param": "Button1_Click" });
})
------------------
function del(oA) {
var $oTr = $(oA).parent().parent();
var key = $oTr.attr("key");
if (confirm("您確定要刪除此條記錄嗎?")) {
$.getJSON("AjaxDelUserInfo.aspx", { id: key }, function(data) {
if (data.Success) {
$oTr.remove();
} else {
alert(data.ErrorMessage);
}
})
}
}
----------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (Request["id"] != null)
{
int id = int.Parse(Request.QueryString["id"]);
try
{
BLL.AuthorManager.DeleteAuthorById(id);
Response.Write("{Success:true,ErrorMessage:''}");
}
catch
{
Response.Write("{Success:false,ErrorMessage:'刪除出錯!'}");
}
}
}
===================
登入
$("#btnLogin").click(function() {
// var params = $("#form1").serialize();
// alert(params);
// $.ajax(
// {
// type: "GET",
// url: "/Demo/LoginHandler.aspx",
// data:params,
// success: function(data) {
// alert(data);
// }
// })
// $.get("/Demo/LoginHandler.aspx",{txtUser:$("#txtUser").val(),txtPass:$("#txtPass").val()} ,function(data) {
$.post("/Demo/LoginHandler.aspx",{txtUser:$("#txtUser").val(),txtPass:$("#txtPass").val()} ,function(data) {
//data代表請求返回的內容
alert(data);
$("#id1").html(data);
// });
// $.getJSON("/Demo/LoginHandler.aspx", { txtUser: $("#txtUser").val(), txtPass: $("#txtPass").val() }, function(josn) {
// alert(josn.success);
});
----
LoginHandler.aspx"
protected void Page_Load(object sender, EventArgs e)
{
if (Request["txtUser"] != null && Request["txtPass"] != null)
{
string username = Request.QueryString["txtUser"];
string password = Request.QueryString["txtPass"];
if (username == "admin" && password == "123")
{
Response.Write("11111111111");//{success:true}
}
else
Response.Write("22222222222222");//{success:false}
}
else
Response.Write("{success:false}");
}