C# MVC 实现 ajax 跨域

2021-03-27 02:27

阅读:380

标签:OLE   测试   scripts   ajax 跨域   err   back   ali   生成   cti   

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 = "测试页";
}


    嘿嘿嘿

//控制器

    public class TestController : BaseController
    {
        ///


        /// 跨域测试
        ///

        ///
        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 }) + ")");
        }}

 

C# MVC 实现 ajax 跨域

标签:OLE   测试   scripts   ajax 跨域   err   back   ali   生成   cti   

原文地址:https://www.cnblogs.com/change4now/p/9368306.html


评论


亲,登录后才可以留言!