码迷,mamicode.com
首页 > Web开发 > 详细

Jsonp 传参和对应接口

时间:2016-04-19 13:46:49      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:

var phoneAgent = navigator.userAgent; var urlDomaintest = " ";

function getHref() {  var href = window.location.href;  return href; } var PhoneAgent=

    

$(function () {
 $.ajax({
  async: false,
  url: urlDomaintest + "Home/CloudUserInfo",
  type: ‘GET‘,
  data: { UserName: phoneAgent, UserEmail: getHref() },
  dataType: "jsonp",
  jsonp: "callback",
  success: function (data) {
   console.log("success");
    if (data.Status==1)
    {
        var docSpan = document.getElementById("NumSpan");
        docSpan.innerHTML = data.ResultNum;
    }
    else
    {
        var docSpan = document.getElementById("NumSpan");
        docSpan.innerHTML = "3500";
    }
  }
 })
});

public ActionResult CloudUserInfo(string callback, string UserName, string UserEmail)
        {
            AjaxResult<string> jsonResult = new AjaxResult<string> { Status = -1, ResultNum = 0, Data = "" };
            try
            {
                ApplicationDbContext dbContext = new ApplicationDbContext();
                CloudQaUser cuInfo = new CloudQaUser();
                cuInfo.UserEmail = UserEmail;
                cuInfo.UserName = UserName;
                cuInfo.CreateTime = DateTime.Now;
                dbContext.CUerInfo.Add(cuInfo);
                if (dbContext.SaveChanges() > 0)
                {
                    //发邮件
                    jsonResult.Status = 1;
                    SendGuRuEmail(cuInfo.UserEmail);
                }
            }
            catch (Exception ex)
            {
                jsonResult.Status = 0;
              
            }
            //return Json(jsonResult, JsonRequestBehavior.AllowGet);
            return JavaScript(string.Format("{0}({1});", callback, Newtonsoft.Json.JsonConvert.SerializeObject(jsonResult)));
        }

Jsonp 传参和对应接口

标签:

原文地址:http://www.cnblogs.com/hanxingli/p/5407549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!