.net Core AJAX使用Header传递参数,以JsonResult返回信息

function postHeader()

{

    $.ajax({

          url : "/myTest/PostHeader?time="+ (new date()).getTime(),

          beforeSend :function (xhr){

                     xhr.setRequestHeader("myValue ","aaa");

            },

            type:"Get",

            success:function(data)

             {

                     alert(data);

              }

    });

}

 

 

 

 

public IActionResult GetAjaxValue([FromHeader] string  myValue )

{

     // JsonResult jr=new JsonResult(new { Name="张三",value=MyValue});

     // return jr;

    return Json(new { Name="张三",value=MyValue});  // 效果和上面一样

}

 

posted @ 2019-07-09 22:19  酒沉吟  阅读(791)  评论(0编辑  收藏  举报