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
Post a Comment