zoukankan      html  css  js  c++  java
  • 跨域问题

    当利用ajax请求本地,如 http://192.168.112.114:8081/api/getlist?PageIndex=1出现跨域问题提示:

     XMLHttpRequest cannot load http://192.168.112.114:8081/api/getlist?PageIndex=1. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8020' is therefore not allowed access. 

    跨域组织是浏览器的行为,查了一下解决方法如下:


    1、用jsonp方式去访问
    2、只需要在NodeJS服务器中添加几个响应报文即可完成
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");

    如果使用mui中的getJson()方法对于res.header("Access-Control-Allow-Headers", "X-Requested-With");是有兼容性问题的,会发出两次请求

  • 相关阅读:
    柱状图最大的矩形
    单词搜索
    最小覆盖子串
    颜色分类
    编辑距离
    X的平方根
    二进制求和
    最大子序和
    N皇后
    java8-14-时间API
  • 原文地址:https://www.cnblogs.com/jolene/p/6105160.html
Copyright © 2011-2022 走看看