A
A
Alexey Bespalov2019-02-25 06:51:23
JavaScript
Alexey Bespalov, 2019-02-25 06:51:23

How can I pass the user in ajax request to 1C?

Greetings!
I make ajax GET request from js to 1C. There is an http service that gives the answer.
To get the necessary data, I just need to enter the following line in the browser:
localhost/base/hs/api/GetInfoByTel/?tel=9635123123
There will be a question about entering a user and password. After entering, the server will give a response.
Is it possible to make such a request directly from JS?
Now I'm getting the error "tatus Code: 401 Unauthorized".
But I don't know how to pass user and password. Tell?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Somewhere Intech, 2019-02-25
@john36allTa

If simple authorization, then you can try this:

$.ajax
({
  type: "GET",
  url: "http://localhost/base/hs/api/GetInfoByTel/?tel=9635123123",
  dataType: 'json',
  async: false,
  headers: {
    "Authorization": "Basic " + btoa("userName:password")
  },
  success: function (e){
    console.log(e); 
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question