• C# MVC 实现 ajax 跨域


    dataup.js
    $(function() {

        $.ajax({
            url: "http://localhost:1266/test/t",
            data: { "a": 1, "b":2, "c": 3 },
            dataType: "jsonp",
            jsonp: "callback",  //Jquery生成验证参数的名称
            timeout: 3000,
            crossDomain: true,
            error: function (a, b, c) {
                if ("timeout" == c) {
                    alert("超时");
                } else {
                    console.log(c);
                }
            },
            success: function (json) {
                alert(json.code+",a="+json.a);
            }
        });
    });


    html:

    @{
        ViewBag.Title = "测试页";
    }
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>

    <body>
        嘿嘿嘿
    </body>
    <script src="~/Comtent/Js/dataup.js"></script>

    //控制器

        public class TestController : BaseController
        {
            /// <summary>
            /// 跨域测试
            /// </summary>
            /// <returns></returns>
            public ActionResult T()
            {
                var a = Request["a"];
                var b = Request["a"];
                var c = Request["a"];
                return Content(Request["callback"] + "(" + JsonConvert.SerializeObject(new { code = 0, a = a, b = b, c = c }) + ")");
            }}

  • 相关阅读:
    8.16
    8.6 总结
    Educational Codeforces Round 45 (Rated for Div. 2)
    Codeforces Round #487 (Div. 2)
    Codeforces Round #485
    codeforces Avito Code Challenge 2018
    MySQL索引知识面试题
    使用多线程优化复杂逻辑以及数据量多处理
    elasticsearch 和Ik 以及 logstash 同步数据库数据
    linux 安装elasticsearch步骤以及入的坑
  • 原文地址:https://www.cnblogs.com/change4now/p/9368306.html
Copyright © 2020-2023  润新知