0

I write a new application to get Microsoft Product. A found in rg-adguard.net can get link max speed from Microsft. So, I tried to create a site same rg-adguard.net but require connect to rg-adguard.net to get Microsft products ISO file. You can see a code look like this:

    var url = 'https://tb.rg-adguard.net/php/get_version.php';

    $.get(
        url,
        "type_id=" + type_id,
        function (result) {
            if (result.type == 'Error base SQL') {
                alert('Error base SQL');
                return(false);
            }
            else {
                var options = ''; 

                $(result.versions).each(function() {
                    options += '<option value="' + $(this).attr('version_id') + '">' + $(this).attr('name') + '</option>';
                });

                $('#version_id').html('<option value="0">- ' + selversion + ' -</option>'+options);
                $('#version_id').attr('disabled', false);
                $('#edition_id').html('<option value="0">- ' + seledition + ' -</option>'+options);
                $('#edition_id').attr('disabled', true);
                $('#language_id').html('<option>- ' + sellanguage + ' -</option>');
                $('#language_id').attr('disabled', true);
                $('#arch_id').html('<option>- ' + selachitecture + ' -</option>');
                $('#arch_id').attr('disabled', true);   
            }
        },
        "json"
    );
});

I tried on my website is: https://sharengay.com But it shows an error look like:

Failed to load https://tb.rg-adguard.net/php/get_version.php?type_id=1: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://sharengay.com' is therefore not allowed access.

How to pass and can get data?

Ave
  • 4,338
  • 4
  • 40
  • 67
  • Hi @smith. I was tried all method. From: to CORS – Ave May 01 '18 at 21:15
  • 1
    This is an error related to cross origin in the browser. You could use a local url/page in your JavaScript get(). The local page could then use Curl to get the results from the remote location. – user9189147 May 01 '18 at 21:16
  • im not a js guy but that worked for me in the past , you could access the variable via php without an issue, so you could access it that way –  May 01 '18 at 21:17
  • The PHP script has to be in the `sharengay.com` domain. – Barmar May 01 '18 at 21:27
  • No, PHP script on `rg-adguard.net`. I tried to send a new request. `rg-adguard.net` return result. – Ave May 01 '18 at 21:31

1 Answers1

0

You need to set an Access-Control-Allow-Origin header. Add this at the top of your PHP file:

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

Also, if you think that is insecure then check this question out: how to bypass Access-Control-Allow-Origin?

Paul Roub
  • 36,322
  • 27
  • 84
  • 93