Jquery异步请求简单实例(转)
本文引用自Xingsoft。
一、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代码:

{
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.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);
}
});
});
后台代码:

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异步请求数据实例代码
一.Jquery向aspx页面请求数据 前台页面JS代码: 代码如下: $("#Button1").bind("click", function () { $. ...
- jQuery异步请求(如getJSON)跨域解决方案
相信大家在使用jQuery异步请求非自己网站内相对资源(通过别人站点上的URL直接读取)使经常会遇到如下错误吧,实际上这些错误都是浏览器安全机制“搞的鬼”,才让我们开发路上遇到了拦路虎. 当你直接在浏 ...
- jQuery异步请求模拟IE登录网站
具体请求的登录验证页面后台逻辑处理,这里我们忽略,不在我们的学习范围内:关键的是使用jQuery异步请求方法,如下例子: <%@ Page Language="C#" Aut ...
- 实现在Android简单封装类似JQuery异步请求
在android开发中经常会使用异步请求数据,通常会使用handler或者AsyncTask去做,handler 配合message 使用起来比较麻烦,AsyncTask 线程池只允许128个线程工作 ...
- Android简单封装类似JQuery异步请求
在android开发中经常会使用异步请求数据,通常会使用handler或者AsyncTask去做,handler 配合message 使用起来比较麻烦,AsyncTask 线程池只允许128个线程工作 ...
- Ajax异步请求-简单模版
<script type="text/javascript"> window.onload = function () { document.getElementByI ...
- jquery 之ajax,get,post异步请求简单代码模版
$.get( "../cart/cart_list.do", "productId="+productId, fu ...
- jQuery异步请求ajax()之complete参数详解
请求完成后回调函数 (请求success 和 error之后均调用).这个回调函数得到2个参数:XMLHTTPRequest) 对象和一个描述请求状态的字符串("success", ...
随机推荐
- MSP430常见问题之IO端口类
Q1:请问430 的I/O 中断能不能可靠的响应60ns 的脉冲信号, 就是来了一个60ns 的脉冲,430 的中断会有丢失吗?A1:端口支持的最高8M的时钟,无法响应这么快的频率. Q2:430是3 ...
- nginx实现域名重定向
一般网站默认的访问端口为80,当多个域名指向同一个服务器IP时,可以nginx进行重定向,分别指向不同的目的地址或其他主机. 在nginx目录下的conf/vhost子目录下建两个conf文件,hos ...
- linq检索带命名空间的xml
XElement el = XElement.Load(fil); XNamespace ns = "http://schemas.microsoft.com/ado/2009/11/edm ...
- double的值太大,以及补0
当double的值太大的时候,比如1000000000 用DecimalFormat: double d = 1.0E7; System.out.println(new DecimalFormat(& ...
- Android之文字点击链接
定义textView1和textView2并获得组件. String html = "<font color='red'></font>"; html += ...
- 省市数据递归加载到TreeView
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- C#WebBrowser控件使用教程与技巧
获取非input控件的值 webBrowser1.Document.All["控件ID"].InnerText;或webBrowser1.Document.GetElementBy ...
- Eclipse 调试maven test
在eclipse中调试maven test 一般情况下,使用如下方式都不能使myeclipse检测到程序中的断点: 项目 -> Run As -> maven test 或 项目 -> ...
- Swift字典集合
字典表示一种非常复杂的集合,允许按照某个键来访问元素.字典是由两部分集合构成的,一个是键(key)集合,一个是值(value)集合.键集合是不能有重复元素的,而值集合是可以重复的,键和值是成对出现的. ...
- (UVA 11624)Fire!
题目链接 http://vjudge.net/contest/121377#problem/J Joe works in a maze. Unfortunately, portions of the ...