Jquery Ajax 如何实现延时加载 。即很多网站上面的Loading。。。动态提时候,延时几秒,才显示出服务器的响应数据
前台<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="JQUERYAJAX.Login" %><!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 id="Head1" runat="server"> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <title>Login Page</title> <style type="text/css"> #msg { width: 164px; height: 64px; } .msg { background: url('Image/25.gif') no-repeat; } </style> <script language="javascript" type="text/javascript"> $(document).ready(function () {
$("#btnLogin").click(function () { Login(); }); });
function Login() { if (Check()) { LoginSuccess(); } }
function Check() { if ($("#txtUser").val() == "") { alert("The user isn't empty"); $("#txtUser").focus(); return false; } if ($("#txtPassword").val() == "") { alert("The Password isn't empty") $("#txtPassword").focus(); return false; } return true; }
function LoginSuccess() { $.ajax({ type: "POST", url: "checkLogin.aspx?i=" + Math.random(), data: { userName: $("#txtUser").val(), userPwd: $("#txtPassword").val() }, beforeSend: function () { $("#msg").addClass("msg"); }, success: function (data) { $("#msg").removeClass("msg"); $("#msg").html(decodeURI(data)); } }); } </script></head><body> <form id="form1" runat="server"> <div style="margin-left: 32px;"> <a>User:</a><input id="txtUser" type="text" /> </div> <div> <a>Password:</a><input id="txtPassword" type="text" /> </div> <div> <input id="btnLogin" type="button" value="Login" /></div> <div id="msg"> </div> </form></body></html>后台using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;
namespace JQUERYAJAX{ public partial class checkLogin : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string retVal = ""; string userName = Request["userName"]; string userPwd = Request["userPwd"]; if (userName == "ike" && userPwd == "123") { retVal = "Login is success";
} else { retVal = "Login is false"; } Response.Write(retVal);
}
} }}