代码改变世界

Jquery跨域调用后台方法

  Yang-Onion  阅读(265)  评论(0编辑  收藏  举报
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//前端JS
function CallHandlerByJquery()
{
        var url = "http://" + window.location.hostname + "/Helper.ashx?FLAG=2&BIZINST_GUID=276259&callback=?&rand="+Math.random();
        $.ajaxSettings.async = false;
        $.getJSON(url, function (data)
        {
          alert(data.state + "|" + data.msg);
        });
}
     
//后台方法
public void ProcessRequest(HttpContext context)
    {
        string jsonResult = string.Empty;
        string callback = context.Request.QueryString["callback"];
        //业务逻辑
        jsonResult = "{state:'0',msg:'操作失败'}";
    }
    context.Response.ContentType = "application/json";
    context.Response.Write(callback + "(" + jsonResult + ")");
    context.ApplicationInstance.CompleteRequest();

  

努力加载评论中...
home page tracking
NutriSystem Diet
点击右上角即可分享
微信分享提示