zoukankan      html  css  js  c++  java
  • 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 }) + ")");
            }}

  • 相关阅读:
    Java中Runnable和Thread的区别
    git 代理设置
    Android的bitmap和优化
    String、StringBuffer与StringBuilder之间区别
    工作流的一些记录
    UIAutomation调用计算器模拟自动执行
    从客户端(Content="<EM ><STRONG ><U >这是测试这...")中检测到有潜在危险的Request.Form 值。
    泛型
    基础加强
    数据库和ado
  • 原文地址:https://www.cnblogs.com/change4now/p/9368306.html
Copyright © 2011-2022 走看看