add request header on backbone

后端 未结 10 2093
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 08:46

My server has a manual authorization. I need to put the username/password of my server to my backbone request inorder for it to go through. How may i do this? Any ideas? Tha

10条回答
  •  有刺的猬
    2020-12-04 09:29

    One option might be to use the jQuery ajaxSetup, All Backbone requests will eventually use the underlying jQuery ajax. The benefit of this approach is that you only have to add it one place.

    $.ajaxSetup({
        headers: { 'Authorization' :'Basic USERNAME:PASSWORD' }
    });
    

    Edit 2nd Jan 2018 For complex web applications this may not be the best approach, see comments below. Leaving the answer here for references sake.

提交回复
热议问题