首页 > Web开发 > 详细

JSONP跨域

时间:2016-01-05 20:42:17      阅读:232      评论:0      收藏:0      [点我收藏+]
 $.ajax({
            type: "get",
            url: "http://www.it.com.cn/vip/Ajax/AjaxSeneNL.aspx?jsoncallback=?",
            data: { mobile: phonenumber, code: checkcode, type: 2 },
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            dataType: "jsonp",
            success: function (result) {
                if (result && result.state == "0") {
                    alert(result.msg);
                } else {
                    alert("验证码已发送!");
                    var countdown = 120;
                    var obj = setInterval(function () {
                        if (countdown > 0) {
                            countdown = countdown - 1;
                            $(".yanzheng").html(countdown + "秒后重新获取");
                        } else {
                            clearInterval(obj);
                            $(".yanzheng").html("获取验证码");
                        }
                    }, 1000);
                }

            },
            error: function (e) {
                alert("短信通道拥堵请稍后再试");
                return false
            }
        })

 

 

 MVC后台

 

 public ActionResult GetCheckCode(string textPhone,string codestr,int? type)
        {
            Response.AddHeader("Access-Control-Allow-Origin""*");

            var callbackName=Request["jsoncallback"];
            /*验证码加密*/
            var codeMd5 =IM.Common.Security.Md5.EncryptMd5(codestr + "instrument_wqooisjc$3>");
            /*获取验证加密cookie值*/
            var getcode = Com.IM.Utils.CurrentCookie.GetCookieByKey("getcheck");

            var json = new object(); ;
            if (codeMd5 == getcode)
            {
                VIPGetTestCode TestGetCode = new VIPGetTestCode();
                TestGetCode.CookieID = IM.WAP.Common.LoginCookie.GetCookie3I();
                TestGetCode.mobile = textPhone;
                TestGetCode.ip = IM.Common.IMRequest.GetIP();
                TestGetCode.type = Convert.ToInt32(type);
                var testcode = IM.WAP.VIP.BLL.VipLogon.SearchNes(TestGetCode);
                //return Json(new { IsSuccess = testcode.Header.IsSuccess, msg = testcode.Header.Messages },JsonRequestBehavior.AllowGet);
                json = new { IsSuccess = testcode.Header.IsSuccess, msg = testcode.Header.Messages };
            }
            else
            {
                //return Json(new { IsSuccess = false, msg = "校验码错误", val = "cookie中的MD5:" + getcode + ",校验码MD5:" + codeMd5 },JsonRequestBehavior.AllowGet);
                json = new { IsSuccess = false, msg = "校验码错误" };
            }
            var jsonp = callbackName + "(" + IM.Common.JsonSerialize.SerializeObject(json) + ")";
            HttpContext.Response.ContentType = "application/json";
            HttpContext.Response.Write(jsonp);
            return null;

        } 

 

参考网址: 

http://kb.cnblogs.com/page/139725/

http://www.nowamagic.net/librarys/veda/detail/224 

JSONP跨域

原文:http://www.cnblogs.com/nzcblog/p/5103521.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!