本文引用自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代码:

   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异步请求数据实例代码

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

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

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

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

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

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

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

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

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

  7. Ajax异步请求-简单模版

    <script type="text/javascript"> window.onload = function () { document.getElementByI ...

  8. jquery 之ajax,get,post异步请求简单代码模版

    $.get(                        "../cart/cart_list.do", "productId="+productId, fu ...

  9. jQuery异步请求ajax()之complete参数详解

    请求完成后回调函数 (请求success 和 error之后均调用).这个回调函数得到2个参数:XMLHTTPRequest) 对象和一个描述请求状态的字符串("success", ...

随机推荐

  1. iOS下获取用户当前位置的信息

    #import <MapKit/MKMapView.h> @interface ViewController (){ CLLocationManager *_currentLoaction ...

  2. Oracle创建表空间、新建用户和授权

    通过pl/sql以sys用户登录到Oracle数据库上,然后执行菜单:文件/新建/命令窗口 ,打开一个命令窗口然后在该命令窗口中执行脚本创建和删除表空间 . 1.创建表空间 格式:  create t ...

  3. js函数大全

    js函数集·字符串(String) 1.声明 var myString = new String("Every good boy does fine."); var myStrin ...

  4. SharePoint手机App巅峰对决:rShare 挑战 SharePlus

    真是个移动的时代,当我们去百度,Bing,雅虎等搜索引擎,搜索关键字比如“SharePoint iOS”, “SharePoint 安卓”, “SharePoint iPhone”,“SharePoi ...

  5. webstorm卡、闪退以及win10中jdk配置【转】

    原文地址:webstorm卡.闪退以及win10中jdk配置   今天 webstorm 突然一直处于 indexing 索引状态,然后就卡死,重装也无法解决. 搜了一下后,有人说使用 64 位客户端 ...

  6. Warrior!之家与Warrior!博客网站发布

    这个网站从大一下学期就开始做,断断续续,一开始感觉无从下手,做了一个草稿便停止了.最近再拿回来,感觉并没有什么难度,便把它做完了,采用ajax页内跳转,对几个搜索引擎都有seo,目前谷歌搜索“Warr ...

  7. 【ROW_NUMBER 函数(Transact-SQL)】

    [ROW_NUMBER 函数(Transact-SQL)]返回结果集分区内行的序列号,每个分区的第一行从 1 开始. 注释: ROW_NUMBER() OVER (PARTITION BY COL1 ...

  8. JQuery中操作表单和表格

    一:表单应用 1.HTML中的表单大致由三部分组成 (1).表单便签:包含处理表单数据所用的服务端程序URL,以及数据提交到服务器的方法. (2).表单域:包含文本框.密码框.隐藏域.多行文本框.复选 ...

  9. HTML+CSS学习笔记(1) - Html介绍

    HTML+CSS学习笔记(1) - Html介绍 1.代码初体验,制作我的第一个网页 <!DOCTYPE HTML> <html> <head> <meta ...

  10. TTTAttributedLabel 如何将多个字符串高亮显示

    TTTAttributedLabel进行多个字符串的高亮显示. 需要对每个字符串进行匹配,从而得到所有需要高亮的NSRange,然后利用NSMutableAttributedString对每个NSRa ...