Force Safari include Origin header in jQuery GET request

From https://app.example.com I make the following request:

 $.get('https://api.example.com', { foo: 'bar' }) .success(getSuccess) .error(getError); 

It works fine in Chrome and Firefox, but not in Safari. Safari does not fulfill the OPTIONS option request or does not include the Origin: https://app.example.com header, so the server does not return the Access-Control-Allow-Origin: https://app.example.com header.

Is there a way to get Safari to include the Origin header or execute an OPF request before submitting?

+6
source share
1 answer

You can add headers to the HTTP XHR request in the beforeSend event.

Sort of:

 $.ajax({ url: 'https://api.example.com', data: { foo: 'bar' }, beforeSend: function(xhr) { xhr.setRequestHeader("Origin", "https://app.example.com"); } }) .success(getSuccess) .error(getError); 
+1
source

Source: https://habr.com/ru/post/890956/


All Articles