Ajax实例
时间:2010-09-30 来源:Mr Chai
最新在做一个项目用到ajax交互,捣鼓了一会写了一个小实例,贴出来供将要学习Jquery与Ajax朋友分享。
jquery 库最新版下载:jquery-1.4.2min.js
jquery 1.3.2mini版:jquery-1.3.2min.js
中文手册下载地址(超酷版):jquery12api
前台代码:
view plaincopy to clipboardprint?
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajax.aspx.cs" Inherits="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 runat="server">
- <title>Jquery Ajax实例</title>
- <mce:script type="text/javascript" src="script/jquery-142min.js" mce_src="script/jquery-142min.js"></mce:script>
- <mce:script type="text/javascript"><!--
- $(function() {
- $("#dbtn").click(function(){
- $.ajax({
- type: "POST",
- //dataType:"Text",
- url:"Handler.ashx",
- data:{name:"admin",pass:"admin"},
- beforeSend:function(){
- $("#ds").html("loading");
- },
- success: function(msg){
- $("#ds").html("<p>"+msg+"</p>");
- }
- });
- });
- });
- // --></mce:script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <div id="ds"><p>我是AJAX原来的文字!</p></div>
- <input type="button" value="提交AJAX测试" id="dbtn" name="dbtn" />
- </div>
- </form>
- </body>
- </html>
Handler.ashx:
view plaincopy to clipboardprint?
- <%@ WebHandler Language="C#" Class="Handler" %>
- using System;
- using System.Web;
- using System.Data.SqlClient;
- public class Handler : IHttpHandler {
- public void ProcessRequest (HttpContext context) {
- context.Response.ContentType = "text/plain";
- //context.Response.Write("Hello World");
- if (context.Request["name"].ToString() == "admin" && context.Request["pass"].ToString() == "admin")
- {
- context.Response.Write("Y");
- }
- else
- {
- context.Response.Write("N");
- }
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
相关阅读 更多 +