0

I came across this topic: Use of basic authorization in JQuery ajax

I have the same problem. When accessing page directly with browser I can see in the request headers the Authorization header. But I can't send this header with Ajax. I need this header, because I'm writing webserver for embedded platform, and the parse function search for it.

My code is:

$.ajax
  ({
    type: "GET",
    url: "http://192.168.1.233/relay",
    username: username,
    password: password,
    data: {
        relay: "on",
    },
    timeout: 2000,
    success: function (result){
      console.log("success: " + result);
    }

});
  • Did this code come from same domain 192.168.1.233? Otherwise this will be treated as cross domain request by browser. – Sameer Naik Aug 29 '15 at 21:48
  • Forget to tell that I'm using Chrome with plug-in that allows cross-domain requests. – Stefan Mavrodiev Aug 29 '15 at 21:54
  • Are you sure username and password variables are defined somewhere? – Sameer Naik Aug 29 '15 at 22:40
  • Yes I am sure about that. – Stefan Mavrodiev Aug 29 '15 at 23:00
  • I tried your code and was able to see that jquery is sending username and password like this. http://username:password@localhost/a.html?relay=on It is not sending it as Basic Auth header though. See this post for possible solution http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax – Sameer Naik Aug 30 '15 at 00:43

0 Answers0