0

I want to get a URL with Ajax like this:

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

The error is this:

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.

As I've tried to search about this problem. But I couldn't, for example these links: https://www.daniweb.com/web-development/php/threads/461902/php-header-is-not-working-for-access-control-allow-origin No 'Access-Control-Allow-Origin' header is present on the requested resource error

Recommends that place this code on top of Php file:

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

But not worked. this is my source code(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";
    ?>

How to solve this problem?

Community
  • 1
  • 1
ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112

1 Answers1

3

Simply add this code to .htaccess file:

<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
 </IfModule>
ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112