• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Ajax基础配置使用教程_jquery

jquery 搞代码 7年前 (2018-06-12) 150次浏览 已收录 0个评论

Ajax定义为“Asynchronous JavaScript + XML”的简称,也就是异步的javaScript和XML处理。从原理上看,主要是Ajax可以通过调用HttpRequest实现与服务器的异步通讯,并最终在网页中实现丰富友好的用户界面
Ajax使用初步,配置步骤
1.把Ajax.dll copy到应用系统bin目录下,然后在工程引用中引用Ajax.dll,如果没有的话可以下载
/Files/singlepine/Ajax.rar
2.配置web.config,添加如下信息

Ajax基础配置使用教程_jquery<httpHandlers>
Ajax基础配置使用教程_jquery  
<add verb=”POST,GET” path=”ajax/*.ashx” type=”Ajax.PageHandlerFactory, Ajax” />
Ajax基础配置使用教程_jquery
</httpHandlers>

3.假设应用系统叫Document,目录格式为Pages/AjaxTest
4.在Pages/AjaxTest下建立cs文件AjaxMethod.cs,添加如下方法

Ajax基础配置使用教程_jquery//[Ajax.AjaxMethod]
Ajax基础配置使用教程_jquery
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
Ajax基础配置使用教程_jquery
public static string GetNIVNumber(string str)
Ajax基础配置使用教程_jqueryAjax基础配置使用教程_jquery
Ajax基础配置使用教程_jquery{
Ajax基础配置使用教程_jquery 
return str;
Ajax基础配置使用教程_jquery}

5.在Pages/AjaxTest下建立页面AjaxForm.aspx

Ajax基础配置使用教程_jquery<html>
Ajax基础配置使用教程_jquery 
<HEAD>
Ajax基础配置使用教程_jquery  
<title>AjaxForm</title>
Ajax基础配置使用教程_jquery  
<meta name=”GENERATOR” Content=”Microsoft Visual Studio .NET 7.1″>
Ajax基础配置使用教程_jquery  
<meta name=”CODE_LANGUAGE” Content=”C#”>
Ajax基础配置使用教程_jquery  
<meta name=”vs_defaultClientScript” content=”JavaScript”>
Ajax基础配置使用教程_jquery  
<meta name=”vs_targetSchema” content=”http://schemas.microsoft.com/intellisense/ie5&#8243;>
Ajax基础配置使用教程_jqueryAjax基础配置使用教程_jquery  
<script language=”javascript”>Ajax基础配置使用教程_jquery
Ajax基础配置使用教程_jquery  
function testAjax(owner, item, evt)
Ajax基础配置使用教程_jqueryAjax基础配置使用教程_jquery  
Ajax基础配置使用教程_jquery{
Ajax基础配置使用教程_jquery   
var first=document.getElementById(txtfirst);
Ajax基础配置使用教程_jquery   AjaxMethod.GetNIVNumber(first.value,callback_GetNIVNumber);
Ajax基础配置使用教程_jquery  }

Ajax基础配置使用教程_jquery  
function callback_GetNIVNumber(res)
Ajax基础配置使用教程_jqueryAjax基础配置使用教程_jquery  
Ajax基础配置使用教程_jquery{
Ajax基础配置使用教程_jquery   
var obj=document.getElementById(txtsecond);   
Ajax基础配置使用教程_jquery   obj.value
=res.value;    
Ajax基础配置使用教程_jquery  }

Ajax基础配置使用教程_jquery  
</script>
Ajax基础配置使用教程_jquery 
</HEAD>
Ajax基础配置使用教程_jquery 
<body MS_POSITIONING=”GridLayout”>
Ajax基础配置使用教程_jquery  
<form id=”Form1″ method=”post” runat=”server”>
Ajax基础配置使用教程_jquery   
<INPUT style=”Z-INDEX: 101; LEFT: 208px; POSITION: absolute; TOP: 40px” type=”button” value=”Button”
Ajax基础配置使用教程_jquery    onclick
=”testAjax();”>
Ajax基础配置使用教程_jquery   
<asp:TextBox id=”txtfirst” style=”Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 40px” runat=”server”></asp:TextBox>
Ajax基础配置使用教程_jquery   
<asp:TextBox id=”txtsecond” style=”Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 72px” runat=”server”></asp:TextBox>
Ajax基础配置使用教程_jquery  
</form>
Ajax基础配置使用教程_jquery 
</body>
Ajax基础配置使用教程_jquery
</HTML>
Ajax基础配置使用教程_jqueryprotected System.Web.UI.WebControls.TextBox txtfirst;
Ajax基础配置使用教程_jquery
protected System.Web.UI.WebControls.TextBox txtsecond;
Ajax基础配置使用教程_jquery
private void Page_Load(object sender, System.EventArgs e)
Ajax基础配置使用教程_jqueryAjax基础配置使用教程_jquery
Ajax基础配置使用教程_jquery{
Ajax基础配置使用教程_jquery 
//注册,其中Document.Pages.AjaxTest.AjaxMethod为AjaxMethod.cs方法所在的命名空间
Ajax基础配置使用教程_jquery
 Ajax.Utility.RegisterTypeForAjax(typeof(Document.Pages.AjaxTest.AjaxMethod));
Ajax基础配置使用教程_jquery}

然后运行就可以了,
实现效果:在第一个textbox中输入内容,点击button,就把内容显示到第二textbox中。这只是一个简单的示例,还可以修改调用方法,从数据库读取以及更复杂的操作

欢迎大家阅读《Ajax基础配置使用教程_jquery》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Ajax基础配置使用教程_jquery
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址