zoukankan      html  css  js  c++  java
  • ajax 第二节jquery版

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    
        <script src="js/jquery-1.8.2.min.js"></script>
        <script type="text/javascript">
    
            $(function () {
    
    
                $("#btn").click(
                           function () {
    
    
                               if (XMLHttpRequest) {
    
    
                                   var xhr = new XMLHttpRequest();
    
                               }
                               else {
    
                                   //ie  5 6 
    xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("get", "handler1.ashx?name=1", true); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { $("#test1").val(xhr.responseText); } } } } ); $("#btn1").click( function () { //jQuery.get(url, [data], [callback], [type]) //参数 标注 : url,参数 {键值对},回调函数,返回内容格式 : xml, html, script, json, text, _default $.get("handler1.ashx?name=1", {}, function (data) { $("#test1").val(data); },"text") } ); $("#btn2").click( function () { // 参考get $.post("handler1.ashx", { "name": "1" }, function (data) { $("#test1").val(data); },"text") } ); $("#btn3").click( function () { // 这种写法 传递的参数都在 data //1.文本:"uname=alice&mobileIpt=110&birthday=1983-05-12" //2.json对象:{uanme:'vic',mobileIpt:'110',birthday:'2013-11-11'} //3.json数组: // [ // {"name":"uname","value":"alice"}, // {"name":"mobileIpt","value":"110"}, // {"name":"birthday","value":"2012-11-11"} //] $.ajax( { type : "GET", url: "handler1.ashx", data :"name=1&name=2", success : function(msg){ $("#test1").val(msg); } }) } ); }) </script> </head> <body> <input type="button" id="btn" value="ajax传统写法" /> <input type="button" id="btn1" value="ajax--jquery写法get" /> <input type="button" id="btn2" value="ajax--jquery写法post" /> <input type="button" id="btn3" value="ajax--jquery写法options" /> <input type="text" id="test1" value="3" /> </body> </html>

    一般处理程序

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace WebApplication2
    {
        /// <summary>
        /// Handler1 的摘要说明
        /// </summary>
        public class Handler1 : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
    
              string a =  context.Request["name"].ToString();
                context.Response.ContentType = "text/plain";
                context.Response.Write(a);
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
  • 相关阅读:
    ffmpeg使用中文使用+解释
    CentOS GCC升级到4.6.1(转)
    C#委托与直接调用方法区别
    微软面试题,倒置数组
    MSDN中介绍的图片格式
    你们的学校是几流
    VS代码模版
    正则表达式
    Visual Studio 2010中添加项目模板
    泛型详解
  • 原文地址:https://www.cnblogs.com/xh0626/p/5005361.html
Copyright © 2011-2022 走看看