0

So I have bee struggling for this almost a day. I want to make request to my website using ajax, so here's what I did

var url = 'http://www.mywebaddress.eu/medicines/';
$.ajax({
                crossDomain: true,
                jsonpCallback: 'test',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name=csrf-token]').attr('content')
                },
                url: url,
                method: 'GET', // Type of response and matches what we said in the route
                success: function (response) { // What to do if we succeed
                    // console.log(response);
                    // $(".animalNumber").val(response.number);
                    // $(".breed").val(response.name);
                    // var birthday = new Date(response.birthday).getTime();
                    // var age = getAge(birthday);
                    // $(".animalAge").val(age);
                    $('#quantity').attr({
                        "max": response.balance
                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log("error = " + errorThrown + " " + textStatus + " " + jqXHR);
                }
            });

Sadly when I open console I saw this

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at url. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). As you can see I already added this
headers: {
                    'X-CSRF-TOKEN': $('meta[name=csrf-token]').attr('content')
                },

So what's wrong?

David
  • 3,055
  • 4
  • 30
  • 73
  • 3
    The server still needs to allow you accessing a resource Cross Domain, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS – m90 Dec 30 '17 at 08:59
  • 1
    Ya, this has to be fixed server side – A. Wolff Dec 30 '17 at 09:00
  • 1
    [Cross Site Request Forgery](https://en.wikipedia.org/wiki/Cross-site_request_forgery) != [Cross Origin Resource Sharing](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) – Andreas Dec 30 '17 at 09:00

0 Answers0