{"id":8099,"date":"2015-11-26T13:38:30","date_gmt":"2015-11-26T13:38:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/how-to-set-custom-header-for-pouchdb-ajax-requests-open-source-projects-pouchdb-pouchdb\/"},"modified":"2022-08-30T15:03:01","modified_gmt":"2022-08-30T15:03:01","slug":"how-to-set-custom-header-for-pouchdb-ajax-requests-open-source-projects-pouchdb-pouchdb","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/how-to-set-custom-header-for-pouchdb-ajax-requests-open-source-projects-pouchdb-pouchdb\/","title":{"rendered":"How to set custom header for PouchDB ajax requests?-open source projects pouchdb\/pouchdb"},"content":{"rendered":"<p>I&#8217;m using PouchDB 3.2.1. I&#8217;m trying to set <code>Authorization<\/code> header for all ajax requests:<\/p>\n<pre><code>db.local = new $window.PouchDB(POUCHDB_NAME);\n\ndb.remote = new $window.PouchDB(COUCHDB_URI, {\n    skipSetup: true,\n    ajax: {\n        headers: {\n            'Authorization': 'Basic ' + $window.btoa('admin:admin')\n        }\n    }\n});\n\n\/\/ Replication\ndb.local.sync(db.remote, {\n    live : true,\n    retry: true\n});\n<\/code><\/pre>\n<p><strong>But it doesn&#8217;t works. See the screenshot:<\/strong><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/xLXp7.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m using PouchDB 3.2.1. I&#8217;m trying to set Authorization header for all ajax requests: db.local = new $window.PouchDB(POUCHDB_NAME); db.remote = new $window.PouchDB(COUCHDB_URI, { skipSetup: true, ajax: { headers: { &#8216;Authorization&#8217;: &#8216;Basic &#8216; + $window.btoa(&#8216;admin:admin&#8217;) } } }); \/\/ Replication db.local.sync(db.remote, { live : true, retry: true }); But it doesn&#8217;t works. See the screenshot:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8099","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8099"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8099\/revisions"}],"predecessor-version":[{"id":8624,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8099\/revisions\/8624"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}