zoukankan      html  css  js  c++  java
  • jquery ajax



    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        
    <title></title>
        
    <script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
       
    <script type="text/javascript">
           
    function LoadData() {

               
    var data = "";
               $(
    "#alldata").html("");
          $.getJSON(
    "Handler1.ashx"""function (json) {

                   
    /*
                   $.each(json,function(i){
                   $("#alldata").append("<li>城市:"+json[i].city+"&nbsp; 面积:"+json[i].mianji+"</li>");
                   });
                   
    */
                   
    for (var j = 0; j < json.length; j++) {
                       $(
    "#alldata").append("<li>城市:" + json[j].city + "&nbsp; 面积:" + json[j].mianji + "</li>");
                   }
                       })


           }
           
    function LoadDataajax() {
               $(
    "#alldata").html("");
               $.ajax({
                   type: 
    "get",
                   url: 
    "Handler1.ashx",
                   data: 
    "",
                   success: 
    function (json) {
                  
    var jsondata = eval(json);
                       
    for (var j = 0; j < jsondata.length; j++) {
                           $(
    "#alldata").append("<li>城市:" + jsondata[j].city + "&nbsp; 面积:" + jsondata[j].mianji + "</li>");
                       }
                }
               });
               
               
           
           }
       
    </script>
    </head>

    <body >
        
    <form id="form1" runat="server">
       
        
    <div>
          
    <ul id="alldata"></ul>
          
    <input type="button" value="获取数据"  onclick="LoadData()"/>
          
    <input type="button" value="ajax 获取数据" onclick="LoadDataajax()" />
        
    </div>
        
    </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace WebApplication2
    {
        
    /// <summary>
        
    /// Summary description for Handler1
        
    /// </summary>
        public class Handler1 : IHttpHandler
        {

            
    public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType 
    = "text/plain";
                
    string jsondata = @"[
                              {'city':'北京','mianji':16800,'renkou':1600},
                              {'city':'上海','mianji':6400,'renkou':1800}
                              ]
    ";
                context.Response.Write(jsondata);
            }

            
    public bool IsReusable
            {
                
    get
                {
                    
    return false;
                }
            }
        }
    }
  • 相关阅读:
    公共开发中js代码的管理
    利用kibana插件对Elasticsearch进行映射
    利用kibana插件对Elasticsearch进行批量操作
    利用kibana插件对Elasticsearch进行文档和索引的CRUD操作
    elasticsearch搜索框架的安装相关
    python面试必问 知识整理
    Selenium定位不到元素的解决方法—iframe挡住了去路
    python 几个简单算法详解
    爬虫突破封禁常用方法
    转载:使用Tornado+Redis维护ADSL拨号服务器代理池
  • 原文地址:https://www.cnblogs.com/gwazy/p/1590791.html
Copyright © 2011-2022 走看看