菜鸟求助AJAX简单例子一个

z_sure521 2012-02-13 09:26:29
小弟想学学AJAX!!但是苦于代码整不明白!!!
求助AJAX简单例子一个,最好是c#的代码例子
PS:不要W3CSCHOOL的东西,弄不明白!!
跪谢给位大神!!!
谁的好用分全送上!!!
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
z_sure521 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wzs_xyz 的回复:]
简单例子:
function clickEvent()
{
var str="AJAX";
var xmlhttp;
if (window.XMLHttpRequest)// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveX……
[/Quote]
等我先試試哈,一會給分別急
z_sure521 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zsx841021 的回复:]
http://dotnetguts.blogspot.com/2008/06/simple-ajax-example-of-aspnet-ajax.html
[/Quote]
等我先試試哈,一會給分別急
z_sure521 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gnik2018 的回复:]
在开发之前我们得进行准备

1、下载ajaxpro.dll,并将其dll引用到项目中,此dll可以到http://www.okajax.com下载。

2、在webconfig的 <system.web>下加上
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerF……
[/Quote]
等我先試試哈,一會給分別急
未知数 2012-02-13
  • 打赏
  • 举报
回复
简单例子:
function clickEvent()
{
var str="AJAX";
var xmlhttp;
if (window.XMLHttpRequest)// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)//表示提交已完成
{
alert(xmlhttp.responseText);//弹出从后台传递过来的值
}
}
xmlhttp.open("post","other.aspx?str="+str+"&type=info",true);//str为传递的字符串,type为设置的标志
xmlhttp.send();
}
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["type"] == "info")//根据在url中设置的标志判断是否是匹配的回传
{
string theString = Request.QueryString["str"];//theString即获取到的字符串
Response.Write("text from Ajax");//将字符串再写往客服端
Response.End();
}
}
三石-gary 2012-02-13
  • 打赏
  • 举报
回复
http://dotnetguts.blogspot.com/2008/06/simple-ajax-example-of-aspnet-ajax.html
gnik2018 2012-02-13
  • 打赏
  • 举报
回复
在开发之前我们得进行准备

1、下载ajaxpro.dll,并将其dll引用到项目中,此dll可以到http://www.okajax.com下载。

2、在webconfig的 <system.web>下加上
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers>

3、在Page_Load中添加
private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebApplication1.WebForm1));
}

4、我们可以在服务器端的CS文件中写下函数,如:
[AjaxMethod]
public static string gettext(string str)
{
return str;
}

但是要说明的是,每个ajax函数定义前必须加上[AjaxMethod]。

5、调用的时候就可以用以下方式进行
<script>
function test()
{
alert(WebApplication1.WebForm1.gettext(‘ajax_Test’).value);
}
</script>

WebApplication1.WebForm1为当前窗体,gettext()是我们在cs文件中写的函数。

下面给出完整的代码:
aspx页面

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" Response.ContentType= "text/xml">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function ss()
{
alert(WebApplication1.WebForm1.gettext(‘liutaotest’).value);
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
<div id="div1">
</div>
<a href="javascript:" onclick=’ss()’>test</a>
</form>
</body>
</HTML>

cs文件:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using AjaxPro;
using System.Management;

namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{

private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebApplication1.WebForm1));
}

[AjaxMethod]
public static string gettext(string sss)
{
string ss = sss;

return ss;
}






#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 – 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}



52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧