一、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 () { $. ...

  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. jQuery异步请求模拟IE登录网站

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

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

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

随机推荐

  1. 网络编程——TCP协议的三次握手和四次挥手

    三次握手原理解析 TCP握手协议在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接. 第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND ...

  2. 关键字 final

    package com.zyw.reusableClass; import java.util.Random; /** * Created by zyw on 2016/3/26. * from th ...

  3. C# 中的协变和逆变

    作为一个从接触 Unity 3D 才开始学习 C# 的人,我一直只了解一些最基本.最简单的语言特性.最近看了<C# in Depth>这本书,发现这里面东西还真不少,即使除去和 Windo ...

  4. 佛山Uber优步司机奖励政策(1月18日~1月24日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  5. Very simple problem - SGU 111(大数开方)

    分析:使用的是构造新数字法进行不断构造,然后逼近每一位数字,然后使用c++徒手敲了240多行代码,竟然过了........................很有成就感. 代码如下: ========== ...

  6. 在Mapper中进行循环判断

    1.在Bo中将值保存在list中

  7. Jquery 进度条集锦

    http://sc.chinaz.com/tag_jiaoben/JinDuTiao.html?qq-pf-to=pcqq.group

  8. WebForm Repeater的事件、后天数据展示--2017年1月8日

    Repeater的Command操作 1.ItemCommand事件 :在Repeater中所有能触发事件的控件,都会来触发这一个事件 CommandName : 判断点击的是什么按钮,e.Comma ...

  9. thinkphp 比对过去时间距离现在时间多少的问题

    <?php import('ORG.Util.Date');// 导入日期类 $Date = new Date();//实例化类 $time_diff = $Date->timeDiff( ...

  10. bzoj1222: [HNOI2001]产品加工

    注意时间都是 <= 5的.. #include<cstdio> #include<cstring> #include<cstdlib> #include< ...