作家
登录

前端跨域请求原理及实践

作者: 来源: 2017-05-25 11:45:23 阅读 我要评论

'POST'
  •  
  •             data: data, 
  •  
  •             url: 'http://localhost:3001/cors'
  •  
  •             dataType: 'json'
  •  
  •             cache: false
  •  
  •             timeout: 5000, 
  •  
  •             success: function(data) { 
  •  
  •                 console.log(data) 
  •  
  •             }, 
  •  
  •             error: function(jqXHR, textStatus, errorThrown) { 
  •  
  •                 console.log('error ' + textStatus + ' ' + errorThrown); 
  •  
  •             } 
  •  
  •         }); 
  •  
  •     }); 
  •  
  • });  
  • 办事器 3001上对应的处理函数:

    1. app.post('/cors'function(req, res) { 
    2.  
    3.     res.header("Access-Control-Allow-Origin""*"); 
    4.  
    5.     res.header("Access-Control-Allow-Headers""X-Requested-With"); 
    6.  
    7.     res.header("Access-Control-Allow-Methods""PUT,POST,GET,DELETE,OPTIONS"); 
    8.  
    9.     res.header("X-Powered-By"' 3.2.1'
    10.  
    11.     res.header("Content-Type""application/json;charset=utf-8"); 
    12.  
    13.     var data = { 
    14.  
    15.         name: req.body.name + ' - server 3001 cors process'
    16.  
    17.         id: req.body.id + ' - server 3001 cors process' 
    18.  
    19.     } 

    20.   推荐阅读

        PinDemonium通用动态脱壳工具

      一、简介本文是对16年的blackhat大年夜会上PinDemonium通用动态脱壳对象介绍。1. 通用脱壳对象简介通用脱壳对象可以经由过程以下办法实现: -debuggers -kernel modules -hyperv>>>详细阅读


      本文标题:前端跨域请求原理及实践

      地址:http://www.17bianji.com/lsqh/35417.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)