[SalesForce] Apex REST API call from Javascript via Ajax Toolkit

I have created a GET method REST service and trying to Ajax call the service through sforce.connection.remoteFunction from JavaScript. Able to get the Session Id and it hitting the service. But the response was Error 401 Unauthorized. Is there anything I'm missing in the request?

Note: I'm Passing the session Id in the request header.

Attaching my Script:

<script type="text/javascript">
window.onload = setupPage;

function setupPage() {
var result = sforce.connection.login("myloginmailid", "pwd+security token"); 
sforce.connection.init(result.sessionId, 'Service URL'); 
    <!-- Salesforce Remote Connection-->  

    sforce.connection.remoteFunction({
        url : "Service URL",
        requestHeaders: {"Authorization":"Bearer"+__sfdcSessionId, "Content-Type":"application/json", "Connection":"Keep-Alive" },
        method: "GET",
        onSuccess : function(response) {
              alert("Success" +response);  
           },
       onFailure : function(response) {
              alert("Failed" + response)
          }
   });    
</script>

Best Answer

Finally i got the solution,

  1. In the sforce.connection.init method we have to pass the "current Session Id" of the organization from which we are requesting,
  2. As responsive mentioned provide space between Bearer and session id.

Changed line of code:

sforce.connection.init(__sfdcSessionId, 'Service URl');