jquery - XMLHttpRequest is not set by using .setRequestHeader -


i try make cross domain request. able have set http header.

$.ajax({                 type: 'get',                 url: 'api',                 beforesend: function (request)                 {                     request.setrequestheader('authorization', 'basic ...==');                 },                 success: function(data) {                     debugger;                 }             }); 

beforesend method seems invoked 'authorization' header not set. please me figure out?

updated: here received cors headers:

access-control-allow-origin : localhost access-control-allow-credential: true access-control-allow-methods: get, put, post, delete, options 

it looks access-control-allow-headers missing.

make sure api supports cors , authorization allowed request header set. when send options request endpoint api should respond following response headers:

access-control-allow-headers:x-requested-with, content-type, authorization access-control-allow-methods:get, post, put, delete, options access-control-allow-origin:* 

this allows client set x-requested-with, content-type , authorization request headers when calling api method , allows get, post, put, delete, options verbs origin domain.

so in order debug problem start sending options request api endpoint , observe response http headers.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -