JQuery在asp.net中三种ajax传值
1)通过webservice,注意去掉注释[System.Web.Script.Services.ScriptService]这行前的注释
2)通过aspx.cs文件中的静态方法
3)通过aspx文件url
- WebForm1.aspx
- WebForm1.aspx
- Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="asp.net.WebForm1" %>
- <!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></title>
- <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
- <script type="text/javascript">
- function Ws() {
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: "WebService1.asmx/HelloWorld2",
- data: "{name:'xiaoxiao'}",
- dataType: 'json',
- success: function (result) {
- alert(result.d);
- }
- });
- }
- function StaticMethod() {
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: "aspxpage.aspx/SayHello2",
- data: "{name:'xiaoxiao'}",
- dataType: 'json',
- success: function (result) {
- alert(result.d);
- }
- });
- }
- function FromPage() {
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: "dataContent.aspx?nowtime='" + new Date() + "'",
- data: "{}",
- dataType: 'html',
- success: function (result) {
- alert(result);
- }
- });
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <input id="Button1" type="button" value="jquery调用WebService" onclick="Ws()" />
- </div>
- <div>
- <input id="Button2" type="button" value="jquery调用aspx页面静态方法" onclick="StaticMethod()" />
- </div>
- <div>
- <input id="Button3" type="button" value="jquery通过page存储值" onclick="FromPage()" />
- </div>
- </form>
- </body>
- </html>
- 以上是启动页面,WebForm1.aspx.cs没有代码
- WebService1.asmx
- Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- namespace asp.net
- {
- /// <summary>
- /// WebService1 的摘要说明
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
- [System.Web.Script.Services.ScriptService]
- public class WebService1 : System.Web.Services.WebService
- {
- [WebMethod]
- public string HelloWorld()
- {
- return "Hello World"+System.DateTime.Now.ToLongTimeString();
- }
- [WebMethod]
- public string HelloWorld2(string name)
- {
- return "Hello World" + name + System.DateTime.Now.ToLongTimeString();
- }
- }
- }
- 以上是webservice中的代码
- aspxpage.aspx.cs
- Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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 asp.net
- {
- public partial class aspx页面代替ws : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- [WebMethod]
- public static string SayHello()
- {
- return "Hello";
- }
- [WebMethod]
- public static string SayHello2(string name)
- {
- return "Hello"+name;
- }
- }
- }
- 以上是针对第二条 通过aspx.cs中的静态方法 注意方法前要加 [WebMethod],aspxpage.aspx页面没代码.
- dataContent.aspx.cs
- Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.IO;
- namespace asp.net
- {
- public partial class dataContent : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Response.Clear();
- Page.ViewStateMode = ViewStateMode.Disabled;
- if (Request.QueryString["nowtime"] != null)
- {
- string stime = Request.QueryString["nowtime"].ToString();
- Response.Write(stime);
- }
- Response.Flush();
- }
- }
- }
- 以上是针对第三条 用url传值 通过aspx页面保存数据。dataContent.aspx页面没有代码.
JQuery在asp.net中三种ajax传值的更多相关文章
- C#中??和?分别是什么意思? 在ASP.NET开发中一些单词的标准缩写 C#SESSION丢失问题的解决办法 在C#中INTERFACE与ABSTRACT CLASS的区别 SQL命令语句小技巧 JQUERY判断CHECKBOX是否选中三种方法 JS中!=、==、!==、===的用法和区别 在对象比较中,对象相等和对象一致分别指的是什么?
C#中??和?分别是什么意思? 在C#中??和?分别是什么意思? 1. 可空类型修饰符(?):引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空.例如:string str=null; ...
- python笔记-20 django进阶 (model与form、modelform对比,三种ajax方式的对比,随机验证码,kindeditor)
一.model深入 1.model的功能 1.1 创建数据库表 1.2 操作数据库表 1.3 数据库的增删改查操作 2.创建数据库表的单表操作 2.1 定义表对象 class xxx(models.M ...
- ASP.NET中几种加密方法
下面就是ASP.NET中几种加密方法.加密算法有两种,也就是上面提到的MD5和SHA1,这里我举的例子是以MD5为例,SHA1大致相同,只是使用的类不一样. MD5的全称是Message-Digest ...
- ASP.NET的三种开发模式
前言 ASP.NET 是一个免费的Web开发框架,是由微软在.NET Framework框架中所提供的,或者说ASP.NET是开发Web应用程序的类库,封装在System.Web.dll 文件中.AS ...
- iOS开发UI篇—iOS开发中三种简单的动画设置
iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...
- C#中三种定时器对象的比较
·关于C#中timer类 在C#里关于定时器类就有3个1.定义在System.Windows.Forms里2.定义在System.Threading.Timer类里3.定义在System.Timers ...
- 转-Web Service中三种发送接受协议SOAP、http get、http post
原文链接:web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 一.web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 在web服务中,有三种可供选择的发 ...
- ASP.NET提供三种主要形式的缓存
ASP.NET提供三种主要形式的缓存:页面级输出缓存.用户控件级输出缓存(或称为片段缓存)和缓存API.
- jquery取消事件冒泡的三种方法展示
jquery取消事件冒泡的三种方法展示 html代码 <!doctype html> <html> <head> <meta charset="ut ...
随机推荐
- CentOS下vsftp安装、配置、卸载(转载)
看过多个教程,只有这个能完整成功配置: http://www.centoscn.com/image-text/config/2015/0122/4543.html
- JavaWeb---总结(七)HttpServletResponse对象(一)
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象. request和response对象即然代表请求和响应,那我们 ...
- CSS3-transform变形功能
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- JQuery------$.getJSON()方法的使用
html(../Home/Index.cshtml) <body> <button class="Btn">按钮</button> </b ...
- host,nslookup,dig 命令安装
host,nslookup,dig依赖bind包,所以先看一下系统有没有bind包 命令如下:rpm -qa |grep bind 如果没有或者版本太低请升级安装 命令是:yum install bi ...
- Ansible facts
facts组件是Ansible用于采集被管理机器设备信息的一个功能.可以使用setup模块查机器的所有facts信息,可以使用filter来查看指定信息.整个facts信息被包装在一个json格式的数 ...
- ecshop去掉“云服务中心”或者是“模板堂知识库”
ECSHOP开发中心(www.68ecshop.com)教程介绍一下如何去除后台云服务中心菜单: 打开admin/templates/menu.htm,把415行的 document.getEleme ...
- basePath = request.getScheme()+"://"+request.getServerName()+":"+r
basePath = request.getScheme()+"://"+request.getServerName()+":"+r (2014-06-30 1 ...
- CentOS下nginx简单安装
说明:环境 系统:Centos 6 软件包:nginx-1.2.4 配置系统yum源 #/etc/yum.repos.d/ #rm -rf ./* vi localhost.repos.d [yumy ...
- Python之路【第二篇】:Python基础
参考链接:老师 BLOG : http://www.cnblogs.com/wupeiqi/articles/4906230.html 入门拾遗 一.作用域 只要变量在内存中就能被调用!但是(函数的栈 ...