1)通过webservice,注意去掉注释[System.Web.Script.Services.ScriptService]这行前的注释

2)通过aspx.cs文件中的静态方法

3)通过aspx文件url

  1. WebForm1.aspx
  1. WebForm1.aspx
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="asp.net.WebForm1" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6. <title></title>
  7. <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
  8. <script type="text/javascript">
  9. function Ws() {
  10. $.ajax({
  11. type: "POST",
  12. contentType: "application/json; charset=utf-8",
  13. url: "WebService1.asmx/HelloWorld2",
  14. data: "{name:'xiaoxiao'}",
  15. dataType: 'json',
  16. success: function (result) {
  17. alert(result.d);
  18. }
  19. });
  20. }
  21. function StaticMethod() {
  22. $.ajax({
  23. type: "POST",
  24. contentType: "application/json; charset=utf-8",
  25. url: "aspxpage.aspx/SayHello2",
  26. data: "{name:'xiaoxiao'}",
  27. dataType: 'json',
  28. success: function (result) {
  29. alert(result.d);
  30. }
  31. });
  32. }
  33. function FromPage() {
  34. $.ajax({
  35. type: "POST",
  36. contentType: "application/json; charset=utf-8",
  37. url: "dataContent.aspx?nowtime='" + new Date() + "'",
  38. data: "{}",
  39. dataType: 'html',
  40. success: function (result) {
  41. alert(result);
  42. }
  43. });
  44. }
  45. </script>
  46. </head>
  47. <body>
  48. <form id="form1" runat="server">
  49.  
  50. <div>
  51. <input id="Button1" type="button" value="jquery调用WebService" onclick="Ws()" />
  52. </div>
  53. <div>
  54. <input id="Button2" type="button" value="jquery调用aspx页面静态方法" onclick="StaticMethod()" />
  55. </div>
  56. <div>
  57. <input id="Button3" type="button" value="jquery通过page存储值" onclick="FromPage()" />
  58. </div>
  59. </form>
  60. </body>
  61. </html>
  62. 以上是启动页面,WebForm1.aspx.cs没有代码
  63. WebService1.asmx
  64. Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System;
  65. using System.Collections.Generic;
  66. using System.Linq;
  67. using System.Web;
  68. using System.Web.Services;
  69. namespace asp.net
  70. {
  71. /// <summary>
  72. /// WebService1 的摘要说明
  73. /// </summary>
  74. [WebService(Namespace = "http://tempuri.org/")]
  75. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  76. [System.ComponentModel.ToolboxItem(false)]
  77. // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
  78. [System.Web.Script.Services.ScriptService]
  79. public class WebService1 : System.Web.Services.WebService
  80. {
  81. [WebMethod]
  82. public string HelloWorld()
  83. {
  84. return "Hello World"+System.DateTime.Now.ToLongTimeString();
  85. }
  86. [WebMethod]
  87. public string HelloWorld2(string name)
  88. {
  89. return "Hello World" + name + System.DateTime.Now.ToLongTimeString();
  90. }
  91. }
  92. }
  93.  
  94. 以上是webservice中的代码
  95.  
  96. aspxpage.aspx.cs
  97. Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System;
  98. using System.Collections.Generic;
  99. using System.Linq;
  100. using System.Web;
  101. using System.Web.UI;
  102. using System.Web.UI.WebControls;
  103. using System.Web.Services;
  104. namespace asp.net
  105. {
  106. public partial class aspx页面代替ws : System.Web.UI.Page
  107. {
  108. protected void Page_Load(object sender, EventArgs e)
  109. {
  110.  
  111. }
  112. [WebMethod]
  113. public static string SayHello()
  114. {
  115. return "Hello";
  116. }
  117. [WebMethod]
  118. public static string SayHello2(string name)
  119. {
  120. return "Hello"+name;
  121. }
  122. }
  123. }
  124.  
  125. 以上是针对第二条 通过aspx.cs中的静态方法 注意方法前要加 [WebMethod],aspxpage.aspx页面没代码.
  126.  
  127. dataContent.aspx.cs
  128. Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System;
  129. using System.Collections.Generic;
  130. using System.Linq;
  131. using System.Web;
  132. using System.Web.UI;
  133. using System.Web.UI.WebControls;
  134. using System.IO;
  135. namespace asp.net
  136. {
  137. public partial class dataContent : System.Web.UI.Page
  138. {
  139. protected void Page_Load(object sender, EventArgs e)
  140. {
  141. Response.Clear();
  142. Page.ViewStateMode = ViewStateMode.Disabled;
  143. if (Request.QueryString["nowtime"] != null)
  144. {
  145. string stime = Request.QueryString["nowtime"].ToString();
  146. Response.Write(stime);
  147. }
  148. Response.Flush();
  149.  
  150. }
  151. }
  152. }
  153.  
  154. 以上是针对第三条 url传值 通过aspx页面保存数据。dataContent.aspx页面没有代码.

JQuery在asp.net中三种ajax传值的更多相关文章

  1. C#中??和?分别是什么意思? 在ASP.NET开发中一些单词的标准缩写 C#SESSION丢失问题的解决办法 在C#中INTERFACE与ABSTRACT CLASS的区别 SQL命令语句小技巧 JQUERY判断CHECKBOX是否选中三种方法 JS中!=、==、!==、===的用法和区别 在对象比较中,对象相等和对象一致分别指的是什么?

    C#中??和?分别是什么意思? 在C#中??和?分别是什么意思? 1. 可空类型修饰符(?):引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空.例如:string str=null; ...

  2. python笔记-20 django进阶 (model与form、modelform对比,三种ajax方式的对比,随机验证码,kindeditor)

    一.model深入 1.model的功能 1.1 创建数据库表 1.2 操作数据库表 1.3 数据库的增删改查操作 2.创建数据库表的单表操作 2.1 定义表对象 class xxx(models.M ...

  3. ASP.NET中几种加密方法

    下面就是ASP.NET中几种加密方法.加密算法有两种,也就是上面提到的MD5和SHA1,这里我举的例子是以MD5为例,SHA1大致相同,只是使用的类不一样. MD5的全称是Message-Digest ...

  4. ASP.NET的三种开发模式

    前言 ASP.NET 是一个免费的Web开发框架,是由微软在.NET Framework框架中所提供的,或者说ASP.NET是开发Web应用程序的类库,封装在System.Web.dll 文件中.AS ...

  5. iOS开发UI篇—iOS开发中三种简单的动画设置

    iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...

  6. C#中三种定时器对象的比较

    ·关于C#中timer类 在C#里关于定时器类就有3个1.定义在System.Windows.Forms里2.定义在System.Threading.Timer类里3.定义在System.Timers ...

  7. 转-Web Service中三种发送接受协议SOAP、http get、http post

    原文链接:web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 一.web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 在web服务中,有三种可供选择的发 ...

  8. ASP.NET提供三种主要形式的缓存

    ASP.NET提供三种主要形式的缓存:页面级输出缓存.用户控件级输出缓存(或称为片段缓存)和缓存API.

  9. jquery取消事件冒泡的三种方法展示

    jquery取消事件冒泡的三种方法展示 html代码 <!doctype html> <html> <head> <meta charset="ut ...

随机推荐

  1. CentOS下vsftp安装、配置、卸载(转载)

    看过多个教程,只有这个能完整成功配置: http://www.centoscn.com/image-text/config/2015/0122/4543.html

  2. JavaWeb---总结(七)HttpServletResponse对象(一)

    Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象. request和response对象即然代表请求和响应,那我们 ...

  3. CSS3-transform变形功能

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. JQuery------$.getJSON()方法的使用

    html(../Home/Index.cshtml) <body> <button class="Btn">按钮</button> </b ...

  5. host,nslookup,dig 命令安装

    host,nslookup,dig依赖bind包,所以先看一下系统有没有bind包 命令如下:rpm -qa |grep bind 如果没有或者版本太低请升级安装 命令是:yum install bi ...

  6. Ansible facts

    facts组件是Ansible用于采集被管理机器设备信息的一个功能.可以使用setup模块查机器的所有facts信息,可以使用filter来查看指定信息.整个facts信息被包装在一个json格式的数 ...

  7. ecshop去掉“云服务中心”或者是“模板堂知识库”

    ECSHOP开发中心(www.68ecshop.com)教程介绍一下如何去除后台云服务中心菜单: 打开admin/templates/menu.htm,把415行的 document.getEleme ...

  8. basePath = request.getScheme()+"://"+request.getServerName()+":"+r

    basePath = request.getScheme()+"://"+request.getServerName()+":"+r (2014-06-30 1 ...

  9. CentOS下nginx简单安装

    说明:环境 系统:Centos 6 软件包:nginx-1.2.4 配置系统yum源 #/etc/yum.repos.d/ #rm -rf ./* vi localhost.repos.d [yumy ...

  10. Python之路【第二篇】:Python基础

    参考链接:老师 BLOG : http://www.cnblogs.com/wupeiqi/articles/4906230.html 入门拾遗 一.作用域 只要变量在内存中就能被调用!但是(函数的栈 ...