0

I get Cross-Origin Request Blocked: error on requesting with the below code.

$.ajax({
    url: 'https://www.google.com/m8/feeds/contacts/default/full?access_token=' + token.access_token,
    type: 'POST',
    crossOrigin: true,
    crossDomain: true,
    Origin: 'http://localhost',
    Host: 'www.google.com',
    xhrFields: {
        withCredentials: true
        },
    dataType: 'xml',
    'Gdata-version': '3.0',
    'Content-Type': 'application/atom+xml',
    'body': xml,
    }).done(function(data) {
    console.log(data);
});

});

GET method retrieves contacts with jsonp(not for POST method) as datatype without any error but in POST method I get errors.

SO-user
  • 1,458
  • 2
  • 21
  • 43
  • 1
    This will help you http://stackoverflow.com/questions/23053349/getting-cross-origin-block-request-cors-error-when-using-getjson-to-get-play?answertab=active#tab-top – Parth Trivedi Dec 15 '15 at 09:11

1 Answers1

-1

It's easy, you should set server http response header first. It's no business with your front-end javascript code. You need to return this header:

Access-Control-Allow-Origin:*

or

Access-Control-Allow-Origin:your domain
Parth Trivedi
  • 3,802
  • 1
  • 20
  • 40
Rishabh Dixit
  • 41
  • 2
  • 13