M
M
Maxim2016-08-28 22:47:12
JavaScript
Maxim, 2016-08-28 22:47:12

What is wrong with AJAX request?

When executing the request, it gives an error, what is the reason?

XMLHttpRequest cannot load www.openrates.in.ua/rates . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' test ' is therefore not allowed access.

$.ajax({
    type: 'GET',
    url: "http://www.openrates.in.ua/rates",
    dataType: 'json',
    cache: false,
    success: function(data) {
          console.log(data);
    }
});

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2016-06-16
@undeadter

deal with promises. Do not go over quickly, but experiment for a couple of hours and read the documentation.

A
Alexey, 2016-08-28
@alsopub

It is written in English and white - the responding resource does not issue the Access-Control-Allow-Origin header, which is why the response from it is filtered and not passed to the script.

M
Makar Gerasimov, 2016-08-28
@MacFiss

And if in a simple way: the resource does not allow the collection of information
Add to the .htaccess of the donor site:

<IfModule mod_headers.c> 
    Header add Access-Control-Allow-Origin "*"
    Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
    Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
</IfModule>

If you are only getting information, then specify GET

V
Vlad, 2016-08-29
@Result007

Hey! Try this entry before ajax request:

$.ajaxSetup({
  headers: {
    	'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question