Jsonp跨域问题

前端代码:

 $.ajax({
            type: "GET",
            cache: false,
            url: "http://servername/webservice/webservice.asmx/GetSingleInfo",
            data: { strCparent: $("#Equipment_ID").val() },
            dataType: "jsonp",
            //jsonp: "callback",
            jsonpCallback: "OnGetMemberSuccessByjsonp"
        });

后端代码:

   string ret = string.Empty;
    HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";
    string jsonCallBackFunName = HttpContext.Current.Request.Params["callback"].ToString();
    //string jsonCallBackFunName1 = HttpContext.Current.Request.QueryString["callback"].Trim();
     
    //上面代码必须
    //中间代码执行自己的业务操作,可返回自己的任意信息(多数据类型)
 
    BLL.equipment eq_bll = new BLL.equipment();
    List<Model.equipment> equipmentList = new List<Model.equipment>();
    equipmentList = eq_bll.GetModelEquimentList(strCparent);
    ret = JsonConvert.SerializeObject(equipmentList);
 
    //下面代码必须
    HttpContext.Current.Response.Write(string.Format("{0}({1})", jsonCallBackFunName, ret));
    HttpContext.Current.Response.End();

总结:

最重要的是获取自动生成的callback这个参数,然后返回去。

 

转载于:https://www.cnblogs.com/codeDevotee/p/7531966.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值