weixin_33670786 2015-08-25 18:12 采纳率: 0%
浏览 17

卡在CORS问题上

I've looked at so many StackOverflow questions about the 'Access-Control-Allow-Origin' problem that occurs when requesting 'GET' in AJAX.

I'm deployed a simple static application to Heroku by creating a simple PHP script to serve up the HTML file (<?php include_once("home.html"); ?>).

Index.php

<?php header("Access-Control-Allow-Origin: *"); 
      header("Access-Control-Allow-Credentials: true "); 
      header("Access-Control-Allow-Methods: OPTIONS, GET, POST"); 
      header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control"); 
      include_once("home.html"); ?> 

home.html

is just a static html file. js file:

$.ajax({ url: 'http://example.com', 
         type: 'GET', 
         crossDomain: true, 
         success: function(res) { 
                   console.log("hello"); 
                  } 
         })

My site pulls images using AJAX. I've tried everything I can to make my site allow CORS but nothing will work. I have tried changing my headers like so header("Access-Control-Allow-Origin: *"); and even tried editing my .htaccess file.

I'm stuck. I would appreciate some help.

  • 写回答

1条回答 默认 最新

  • 叼花硬汉 2015-08-28 02:23
    关注

    You cannot use credentials and * at the same time. If you want to use credentials in the request, you will need to explicitly list the requesting origin on the server. E.g., Access-Control-Allow-Origin: example.com.

    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)