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 ...
随机推荐
- 为什么要用Markdown写东西
为什么要用Markdown 不用费心去调格式了,比方说题目加粗什么的,删除线什么的,代码也只要四个空格就好了~ 学起来很简单,几乎没什么学习成本,而收益却很大 这几乎快让我我想从cnblog转到简书了 ...
- 第三次作业——个人作业,k米案例分析
第一部分 调研,评测 评测 1.下载并使用 第一次打开,没什么很深的印象,看见"扫一扫",随手就点了,然后就出现了严重的卡顿,大概是刚启动并且第一次启动的原因,后面就还好了.而且第 ...
- 捉襟见肘之NSMutableSet和NSPointerArray
用来学习复习记录,其他优秀的译文,点击这里 一.NSMutableSet NSMutableSet和NSMutableArray存放数据方式分别是无序和有序,这说明,数组是可以通过index获取对象. ...
- GitHub官方介绍(中文翻译)
注:本人亲自翻译,转载请注明出处. 官方链接地址 http://guides.github.com/activities/hello-world/ Hello World 项目在计算机编程界是一项历史 ...
- Distinct
SELECT 指令让我们能够读取表格中一个或数个栏位的所有资料.这将把所有的资料都抓出,无论资料值有无重复.在资料处理中,我们会经常碰到需要找出表格内的不同资料值的情况.换句话说,我们需要知道这个表格 ...
- PHP设计模式-策略模式 转
策略模式(Strategy Pattern) 策略模式是对象的行为模式,用意是对一组算法的封装.动态的选择需要的算法并使用. 策略模式指的是程序中涉及决策控制的一种模式.策略模式功能非常强大,因为这个 ...
- sudo 出现unable to resolve host 解决方法
inux 环境, 假设这台机器名字叫dev(机器的hostname), 每次执行sudo 就出现这个警告讯息:sudo: unable to resolve host dev虽然sudo 还是可以正常 ...
- MySQL学习笔记——约束
1.约束是在表上强制执行的数据检验规则,约束主要用于保证数据库的完整性. 2.当表中数据有相互依赖性时,可以保护相关的数据不被删除. 3.大部分数据库支持下面五类完整性约束: - NOT NULL非空 ...
- php-fpm服务挂掉
今天发了个链接,可能同时在线的人瞬间比较多,结果网站报503错误,回去打开php-fpm错误日志一看,php-fpm服务挂掉了,报如下错误: [04-Apr-2016 15:38:04] NOTICE ...
- GC算法
http://www.brpreiss.com/books/opus5/html/page424.html http://www.brpreiss.com/books/opus5/html/page4 ...