zoukankan      html  css  js  c++  java
  • JSONP跨域

     $.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 

  • 相关阅读:
    离职or not 离职
    RelativeLayout总结
    MVC中小试了一下Jquery
    tricks about andor in python
    【回旋数字】c语言实现
    退役?
    HDU4546 比赛难度
    WEB页面导出为EXCEL文档的方法
    开始→运行→命令
    控制Repeater显示列数
  • 原文地址:https://www.cnblogs.com/nzcblog/p/5103521.html
Copyright © 2011-2022 走看看