JavaScript脚本访问后台服务实例

本文提供了一个JavaScript脚本访问后台服务的实例。通过前端代码展示如何使用AJAX进行GET请求,传递参数到后台处理。后台服务代码为.NET的IHttpHandler实现,接收并解析参数,然后根据参数执行相应操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

js访问后台服务实例


前端代码:

function GetHeatMapFunc()
{
        var s_time = "2017-11-12";
        var s_hour = 8;
        var e_time = "2017-11-13";
        var e_hour = 8;
        $("#map").css("cursor", "wait");

        var urlStr = encodeURI("XXXXXX.ashx?method=ssyq&oper=ToDayRainInfo&Ale=" + s_time + "&oge=" + s_hour + "&phe=" + e_time + "&bna=" + e_hour + "&vins=1&" + Math.random());
        $.ajax({
            type: "get",
            contentType: "application/json;charset=UTF-8",
            url: urlStr,
            success: success,
            error: error
        });
}


function success(data)
{
    S_rainheatmap = data;
    ......
}


function error()
{
    alert("heatmap request error!");
}



后台服务代码

public class XXXXXX : IHttpHandler {


    public struct ParaStrObj
    {
        public string paraStr { get; set; }
    }
    
    //js通过ajax传递参数至该模块
    public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            ///Online Analysis  Func. isoline,isomultipolygon and heatmap of jiangsu,witch by some args.
            string method = System.Web.HttpContext.Current.Request["method"].ToString();
            //Args: time range and rank of rain
            string s_d = System.Web.HttpContext.Current.Request["Ale"].ToString();
            string s_h = System.Web.HttpContext.Current.Request["oge"].ToString();
            string e_d = System.Web.HttpContext.Current.Request["phe"].ToString();
            string e_h = System.Web.HttpContext.Current.Request["bna"].ToString();
            string cls = System.Web.HttpContext.Current.Request["vins"].ToString();


            string begin_date = s_d + " " + s_h + ":00";
            string end_date = e_d + " " + e_h + ":00";
            string rank = cls;
            //根据传参处理相关数据请求
            res = JS_OnlineAnalyse(method, begin_date, end_date, rank, context);
            
        
        context.Response.Write(res);
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值