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传值的更多相关文章

  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. Beta Daily Scrum 第五天

    [目录] 1.任务进度 2.困难及解决 3.燃尽图 4.代码check-in 5.总结 1. 任务进度 学号 今日完成 明日完成 612 完成分享成就到朋友圈,查看当天成就 我的任务完成啦 615 写 ...

  2. Docker入门教程(五)Docker安全

    Docker入门教程(五)Docker安全 [编者的话]DockOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第五篇,介绍了Docker的安全问题,依然是老话重谈,入门者可以通 ...

  3. Linux bash 中,如何将正常信息和错误信息输出到文件

    问题描述: $ command 2>> error $ command 1>> output 是否有方法,在bash同一行,实现输出stderr到error文件,输出stdou ...

  4. uC/OS-II内存(OS_mem)块

    /*************************************************************************************************** ...

  5. WSADATA

    中文名 WSADATA 操作系统 Windows CE 版本: 大于等于1.0 定义位置: Winsock.h 目录 1 说明 2 结构原型 3 参数说明 4 备注 说明编辑 WSADATA结构被用来 ...

  6. 自然语言16_Chunking with NLTK

    Chunking with NLTK 对chunk分类数据结构可以图形化输出,用于分析英语句子主干结构 # -*- coding: utf-8 -*-"""Created ...

  7. 使用Newtonsoft JsonConvert反序列化Json数据到DataTable

    //JsonStr为Json字符串 JArray array = JsonConvert.DeserializeObject(JsonStr) as JArray;//反序列化为数组 ) { Stri ...

  8. 关于Spring常用的注解

    参考文献:http://www.cnblogs.com/xdp-gacl/p/3495887.html 使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationC ...

  9. 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【二】——使用Repository模式构建数据库访问层

    系列导航地址http://www.cnblogs.com/fzrain/p/3490137.html 前言 在数据访问层应用Repository模式来隔离对领域对象的细节操作是很有意义的.它位于映射层 ...

  10. 端口扫描(TCP)

    还待优化... #include <string.h> #include <WinSock.h> #include <stdio.h> #pragma commen ...