cors跨域的前端实现---根据资料整合的

1.服务端

  搁response中增加Access-Control-Allow-Origin:‘*’

  eg:  context.Response.AddHeader("Access-Control-Allow-Origin", "*");

2.前端

  同样发送ajax请求

  $.ajax({

    type:'method'   //GET POST HEAD都行

    url:‘croll-domain-url’,

    xhrFields:{

      withCredentials:true   //允许带cookie跨域

    },

    headers:{...},

    success:function() {...},

    error:function() {...}

  })

  

posted @ 2017-03-15 17:48  百年美  阅读(220)  评论(0编辑  收藏  举报