ASP.NET & Jquery
来源:互联网 发布:北京排名优化公司 编辑:程序博客网 时间:2024/06/05 05:44
AjaxResponse.aspx.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.Services;namespace SmsReminderApp{ public partial class AjaxResponse : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static string GetDate() { return DateTime.Now.ToString(); } }}
AjaxTest.aspx
<div id="Result">Click here for the time.</div><script type="text/javascript"> $(document).ready(function () { // Add the page method call as an onclick handler for the div. $("#Result").click(function () { $.ajax({ type: "POST", url: "AjaxResponse.aspx/GetDate", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { // Replace the div's content with the page method's return. $("#Result").text(msg.d); } }); }); });</script>
########################################################################################################################
Back-end
public partial class AjaxResponse : System.Web.UI.Page { public static string[] UserNameArray; protected void Page_Load(object sender, EventArgs e) { UserNameArray = new string[7] { "testid01", "testid02", "testid03", "testid04", "testid05", "testid06", "testid07" }; } [WebMethod] public static bool CheckUserName(string sUserName) { if (sUserName == "445756176@qq.com") { return true; } else { return false; } }}
Front-end
<a href="" name="links" id="links">Test Link</a> <br /> <asp:textbox runat="server" ID="txtUserName" name="txtUserName"></asp:textbox> <script language="javascript" type="text/javascript"> $(document).ready(function () { $("#links").click(function (e) { e.preventDefault(); if ($("#txtUserName").val() == '') alert("Please enter the UserName"); else sendData($("#txtUserName").val()); }); function sendData(sUserName) { $.ajax({ type: "POST", url: "AjaxResponse.aspx/CheckUserName", data: '{"sUserName":"' + sUserName + '"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { if (msg.d) alert("The User Name is valid"); else alert("The User Name is invalid") }, error: function () { alert("An unexpected error has occurred during processing."); } }); } });</script>
Onclick function
<script type="text/javascript"> var tbnext; function copyText(tbnext) { document.getElementById("txtUserName").value = tbnext; } </script> <a href="" name="links1" id="link1" onclick="copyText('sss')">Test1 Link</a> <br /> <asp:textbox runat="server" ID="txtUserName" name="txtUserName"></asp:textbox>
##########################################################################################################################
Transfer more parameters
Front-end
<script type="text/javascript"> var a; var b; function getdoubles(a,b) { $.ajax({ type: "POST", url: "AjaxResponse.aspx/doublePars", data: '{a:"'+ a +'", b:"' + b +'"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { // Replace the div's content with the page method's return. $("#Result").text(msg.d); } }); } </script> <div onclick="getdoubles(3,8)">ssss</div><div id="Result">Click here for the time.</div>
Back-end
[WebMethod] public static string doublePars(int a , int b) // the web method must be static { int c = a + b; return c.ToString(); }
#####################################################################################################################
- jquery ajax asp.net
- asp.net + jquery
- ASP.NET结合Jquery
- ASP.NET结合Jquery
- asp.net jquery ajax
- jquery for ASP.Net
- ASP.NET & Jquery
- asp.net--JQUERY使用
- jquery+ajax(asp.net)
- ASP.NET AJAX 和 jQuery
- asp.net 与jQuery结合
- asp.net 自动完成 jquery
- Asp.net Jquery Ajax 实例
- jquery ajax与asp.net
- Jquery Ajax for ASP.NET
- jquery 调用 后台 asp.net
- asp.net 调用jquery ajax
- jQuery操作Asp.net控件
- textbox只能输入正整数
- extjs grid添加滚动条
- aspnet_regiis加密的web.config解密工具
- 对文件进行快速简单加密(防小白)
- 数据加密工具设计经验
- ASP.NET & Jquery
- 【转】ExtJS中的grid没有滚动条问题(grid作为form的一个item)
- 如何在Renderer中设置属性
- JS控制文本框只能输入正整数和两位小数点以内的小数
- flex4
- Linux 下关闭防火墙设置
- XAML实例教程系列 - XAML传递参数到值转换类实例
- 演说?忽悠?
- 随笔二十一:浮点运算