簡體   English   中英

沒有用Php標頭解決的請求資源上沒有'Access-Control-Allow-Origin'標頭

[英]No 'Access-Control-Allow-Origin' header is present on the requested resource not solved with Php header

我想要這樣的Ajax URL:

$.ajax({url: "http://techparty.ir/e.php", success: function(result){
        $("#div1").html(result);
    }});

錯誤是這樣的:

XMLHttpRequest cannot load http://techparty.ir/e.php?_=1437826051819. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://domain.com' is therefore not allowed access.

由於我嘗試搜索此問題。 但是我不能,例如這些鏈接: https : //www.daniweb.com/web-development/php/threads/461902/php-header-is-not-working-for-access-control-allow-origin 請求的資源錯誤中沒有“ Access-Control-Allow-Origin”標頭

建議將此代碼放在Php文件頂部:

header("Access-Control-Allow-Origin: *");   

但是沒有用。 這是我的源代碼(e.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");
    echo "ehsan";
    ?>

如何解決這個問題呢?

只需將此代碼添加到.htaccess文件中:

<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
 </IfModule>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM