0

I've tried every example I've seen on stackoverflow and I still cannot get jquery to include the authorization. I am user jQuery 1.11.3. Here is my ajax call

var headers = "Basic "+username+":"+password;
var data = $.ajax({
        type: "GET",
        url: "https://55.55.55.55:6025/users",
        crossDomain: true,
        dataType: 'jsonp',
        beforeSend : function(xhr) {
          xhr.setRequestHeader("Authorization", headers);
        },
        xhrFields: {
          withCredentials: 'true'
        },
        processData: 'false'
})
data.done(function (result) {
    console.log(result);
})
data.fail(function (result) {
    console.log(result);
});

I have also tried this:

var data = $.ajax({
    type: "GET",
    url: "https://104.236.169.12:6025/users",
    crossDomain: true,
    dataType: 'jsonp',
    username: creds[0],
    password: creds[1]
})

Why is this not including an authorization field in the request headers?

I am also using limejs. So if there is some kind of CORS functionality inside that that I am not getting, would someone please point that out?

EDIT

I found this method that seems to be working:

var data = $.ajax({
    type: "GET",
    url: "https://user@email.edu:pass@104.236.169.12:6025/users",
    dataType: 'jsonp'
})

but it sends the credentials in plain text in the http request. Is this a safe method?

Jeremy
  • 1,717
  • 5
  • 30
  • 49
  • 1
    you can't send headers with JSONP. – Kevin B Aug 14 '15 at 21:37
  • See my update. I tried it with just the username and password too – Jeremy Aug 14 '15 at 21:40
  • That doesn't change my first comment. – Kevin B Aug 14 '15 at 21:46
  • Please don't comment on here unless you are going to contribute something that will help me find an answer – Jeremy Aug 14 '15 at 21:47
  • 1
    YOU CANNOT USE `datatype:'jsonp'` IF YOU EXPECT TO SEND HEADERS TO THE SERVER. is that any more clear? I'm trying to help you solve this problem. – Kevin B Aug 14 '15 at 21:48
  • 1
    JSONP requests are done by appending a – Kevin B Aug 14 '15 at 21:49
  • Okay, I'm sorry. I stopped using jsonp on the API and I found something that is working. Thank you – Jeremy Aug 14 '15 at 21:57

0 Answers0