一、Jquery向aspx页面请求数据 
前台页面JS代码: 
代码如下:

$("#Button1").bind("click", function () {
$.ajax({
type: "post",
url: "default.aspx",
data: "name=" + $("#Text1").val(),
success: function (result) {
alert(result.msg);
}
});
});

代码如下:

<input id="Text1" type="text" value='张三'/>
<input id="Button1" type="button" value="提交" />

后台cs代码: 
 代码如下:

protected void Page_Load(object sender, EventArgs e)
{
if (Request["name"] != null)
{
Response.ContentType = "text/json";
Response.Write("{\"msg\":\"" + Request["name"] + "\"}");//将数据拼凑为Json
Response.End();
}
}

二、Jquery向WebService页面请求数据 
 代码如下:

$("#Button2").bind("click", function () {
$.ajax({
type: "post",
contentType: "application/json",
url: "WebService.asmx/HelloWorld",
data: "{name:'" + $("#Text1").val() + "'}",
datatype: "json",
success: function (result) {
alert(result.d);
}
});
});

<input id="Button2" type="button" value="向WebService提交" />

WebService代码 
代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConFormsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld(string name)
{
return "Hello World" + name;
}
}

三、Jquery向ashx请求数据和向页面相同 
Js代码: 
代码如下:

$("#Button3").bind("click", function () {
$.ajax({
type: "post",
url: "Handler.ashx",
data: "name=" + $("#Text1").val(),
success: function (result) {
alert(result.msg);
}
});
});

后台代码: 
代码如下:

<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";
context.Response.Write("{\"msg\":\"Hello World" + context.Request["name"] + "来自handler.ashx\"}");
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}

Jquery异步请求数据实例代码的更多相关文章

  1. Jquery异步请求数据实例

    一.Jquery向aspx页面请求数据 前台页面JS代码: $("#Button1").bind("click", function () { $.ajax({ ...

  2. Jquery异步请求简单实例(转)

    本文引用自Xingsoft. 一.Jquery向aspx页面请求数据 前台页面JS代码:             $("#Button1").bind("click&qu ...

  3. jQuery基础(Ajax,load(),getJSON(),getScript(),post(),ajax(),同步/异步请求数据)

    1.使用load()方法异步请求数据   使用load()方法通过Ajax请求加载服务器中的数据,并把返回的数据放置到指定的元素中,它的调用格式为:   load(url,[data],[callba ...

  4. jQuery异步请求(如getJSON)跨域解决方案

    相信大家在使用jQuery异步请求非自己网站内相对资源(通过别人站点上的URL直接读取)使经常会遇到如下错误吧,实际上这些错误都是浏览器安全机制“搞的鬼”,才让我们开发路上遇到了拦路虎. 当你直接在浏 ...

  5. 实现在Android简单封装类似JQuery异步请求

    在android开发中经常会使用异步请求数据,通常会使用handler或者AsyncTask去做,handler 配合message 使用起来比较麻烦,AsyncTask 线程池只允许128个线程工作 ...

  6. Android简单封装类似JQuery异步请求

    在android开发中经常会使用异步请求数据,通常会使用handler或者AsyncTask去做,handler 配合message 使用起来比较麻烦,AsyncTask 线程池只允许128个线程工作 ...

  7. 使用load()方法异步请求数据

    使用load()方法通过Ajax请求加载服务器中的数据,并把返回的数据放置到指定的元素中,它的调用格式为: load(url,[data],[callback]) 参数url为加载服务器地址,可选项d ...

  8. 解决ajax异步请求数据后swiper不能循环轮播(loop失效)问题、滑动后不能轮播的问题。

    问题描述: 1.我使用axios异步请求后台的图片进行渲染后不能实现循环轮播,也就是loop失效,但是静态写死的情况下不会出现这种问题. 2. 分析: swiper的机制是:初始化的时候将swiper ...

  9. jQuery异步请求模拟IE登录网站

    具体请求的登录验证页面后台逻辑处理,这里我们忽略,不在我们的学习范围内:关键的是使用jQuery异步请求方法,如下例子: <%@ Page Language="C#" Aut ...

随机推荐

  1. machine learning(14) --Regularization:Regularized linear regression

    machine learning(13) --Regularization:Regularized linear regression Gradient descent without regular ...

  2. 什么是Log4j,Log4j详解!

    由于时间紧急,自己就不写了.一下转载链接: https://www.cnblogs.com/ITtangtang/p/3926665.html

  3. vue2 自定义键盘事件

  4. 48、[源码]-Spring容器创建-初始化事件派发器、监听器等

    48.[源码]-Spring容器创建-初始化事件派发器.监听器等 8.initApplicationEventMulticaster();初始化事件派发器: 获取BeanFactory 从BeanFa ...

  5. Update和Select结合统计更新

    Update和Select结合统计更新 update table_a set updatetime=getdate(), name=b.name from (select name,age from ...

  6. Hadoop集群分布搭建

    一.准备工作 1.最少三台虚拟机或者实体机(官网上是默认是3台),我这边是3台 s1: 10.211.55.18 s2: 10.211.55.19 s3: 10.211.55.20 2.安装JDK 3 ...

  7. 小程序官方基础项目api请求

    onLaunch: function () { // 展示本地存储能力 var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now ...

  8. 模拟I2C协议学习点滴之原理框架

    I2C是一种串行总线协议. 目前几种常用的串行总线有UART.SPI和I2C协议.UART协议的总线只有两条,发送(Transmit:TX)和接收(Receive:RX),没有时钟信号,这就要求两位数 ...

  9. SpringMVC 捕获参数绑定失败时的异常

    SpringMVC配置数据验证(JSR-303)中提到了用String类型的域来绑定Ajax中的非法类型的参数. 这样做的目的是一旦发生一种情况,后端可以返回一个自定类的返回值,而不是返回Spring ...

  10. IntelliJ IDEA实时代码模板

    首先,通过 Settings > Editor - Live Templates进入设置窗口 在Abbreviation:中设置缩写,在 Template text:中设置模板内容,通过 Cha ...