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 

  • 相关阅读:
    POJ1006(中国剩余定理)
    Ubuntu16.04安装jupiter
    OpenGL.tutorial06键盘和鼠标
    OpenGL.教程
    OpenGL.Qt532.cube
    Qt551.主窗体Margin
    Qt551.窗口滚动条
    Qt551.OpenGL.ZC简单例子
    Qt5OpenGL.顶点像素大小设置
    OpenGL.Tutorial03_Matrices_测试
  • 原文地址:https://www.cnblogs.com/nzcblog/p/5103521.html
Copyright © 2011-2022 走看看