Jquery异步请求数据实例代码
一、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异步请求数据实例代码的更多相关文章
- Jquery异步请求数据实例
一.Jquery向aspx页面请求数据 前台页面JS代码: $("#Button1").bind("click", function () { $.ajax({ ...
- Jquery异步请求简单实例(转)
本文引用自Xingsoft. 一.Jquery向aspx页面请求数据 前台页面JS代码: $("#Button1").bind("click&qu ...
- jQuery基础(Ajax,load(),getJSON(),getScript(),post(),ajax(),同步/异步请求数据)
1.使用load()方法异步请求数据 使用load()方法通过Ajax请求加载服务器中的数据,并把返回的数据放置到指定的元素中,它的调用格式为: load(url,[data],[callba ...
- jQuery异步请求(如getJSON)跨域解决方案
相信大家在使用jQuery异步请求非自己网站内相对资源(通过别人站点上的URL直接读取)使经常会遇到如下错误吧,实际上这些错误都是浏览器安全机制“搞的鬼”,才让我们开发路上遇到了拦路虎. 当你直接在浏 ...
- 实现在Android简单封装类似JQuery异步请求
在android开发中经常会使用异步请求数据,通常会使用handler或者AsyncTask去做,handler 配合message 使用起来比较麻烦,AsyncTask 线程池只允许128个线程工作 ...
- Android简单封装类似JQuery异步请求
在android开发中经常会使用异步请求数据,通常会使用handler或者AsyncTask去做,handler 配合message 使用起来比较麻烦,AsyncTask 线程池只允许128个线程工作 ...
- 使用load()方法异步请求数据
使用load()方法通过Ajax请求加载服务器中的数据,并把返回的数据放置到指定的元素中,它的调用格式为: load(url,[data],[callback]) 参数url为加载服务器地址,可选项d ...
- 解决ajax异步请求数据后swiper不能循环轮播(loop失效)问题、滑动后不能轮播的问题。
问题描述: 1.我使用axios异步请求后台的图片进行渲染后不能实现循环轮播,也就是loop失效,但是静态写死的情况下不会出现这种问题. 2. 分析: swiper的机制是:初始化的时候将swiper ...
- jQuery异步请求模拟IE登录网站
具体请求的登录验证页面后台逻辑处理,这里我们忽略,不在我们的学习范围内:关键的是使用jQuery异步请求方法,如下例子: <%@ Page Language="C#" Aut ...
随机推荐
- MySQL 新建用户并赋予权限
创建一个用户: create user 'oukele'@'%' identified by 'oukele'; 提示下面所列出的信息的话,得刷新一下权限表 The MySQL server is r ...
- guava字符串工具 Splitter 主要功能是拆分字符串为集合 Map
public class SplitterTest { public static void main(String args[]){ //1.拆分字符串为List集合 String str=&quo ...
- LOJ P10163 Amount of Degrees 题解
每日一题 day6 打卡 Analysis 题目的意思是找在区间[x,y]之间满足能够由k个b的不同次幂相加得到的数的总数.这题的关键是转换进制,之前几道题我们保存的是数的每位数,其实也就是10进制, ...
- The database principal owns a schema in the database, and cannot be dropped. (.Net SqlClient Data Pr
解决microsoft sql server error:15138的方法 http://blog.csdn.net/gray13/article/details/4458523 用sp_change ...
- Gym - 101981E 思维
Gym - 101981EEva and Euro coins 题意:给你两个长度皆为n的01串s和t,能做的操作是把连续k个相同的字符反转过来,问s串能不能变成t串. 一开始把相同的漏看了,便以为是 ...
- 06_去除不需要的字段以及ELK时间轴问题
去除字段只能去除_source中的,不是_source内的无法去除. 去除不必要的字段,不仅可以节省ES的存储内容,同时因为节省了ES的内容,可以加速搜索的速度 Logstash配置去除不需要的字段 ...
- surprise库官方文档分析(三):搭建自己的预测算法
1.基础 创建自己的预测算法非常简单:算法只不过是一个派生自AlgoBase具有estimate 方法的类.这是该方法调用的predict()方法.它接受内部用户ID,内部项ID,并返回估计评级r f ...
- spring boot 扫描 其他jar包里面的 mapper xml
启动类配置扫描 goods.mapper为当前项目mapper路径 ,common.mpper为其他jar包. 1. 2.mybatis.mapper-locations=classpath*:map ...
- 学习C/C++的简单方法
如何学习C++呢.C和C++是很多专业的必修课,尤其对计算机专业来说,更是重中之重.C++语言是早期发展的高级语言,具备执行速度快,语法优美等特点.是底层高效率系统的首选开发语言.今天就和大家分享一下 ...
- a=(1,)b=(1),c=(“1”) 分别是什么类型的数据
(1,)– tuple; (“1”) – str; (1) – int; >>> (2,)(2,)>>> (2)2>>> ("6&quo ...