add request header on backbone

后端 未结 10 2147
伪装坚强ぢ
伪装坚强ぢ 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:42

    1. In the client side, add this before any server communication:

      $.ajaxSetup({
          xhrFields: {
              withCredentials: true
          },
          async: true
      });
      
    2. In the server side add these headers (PHP):

      header('Access-Control-Allow-Origin: http://your-client-app-domain');
      header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
      header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
      header('Access-Control-Allow-Credentials: true');
      

提交回复
热议问题