views:

120

answers:

1

Hey braintrust,

I'm making an ajax call using jQuery's library to an api, which requires a username and password encoded to base64 be added to the header.

here's a basic example:

$.ajax({
    type: "GET",
    contentType: 'application/json',
        beforeSend:function(xhr){
        xhr.setRequestHeader("Authentication", "Basic " + base64EncodedValue);
    }
    url: 'https://api.company.com/uri/',
    complete: function(result) {
       alert(result);
    }
});

But when this fires off, I get a black alert box, so it doesn't appear as if something is coming back. There is no log in the Firebug console that a get ajax request was done.

However, if I remove the beforeSend option, I do see the ajax request get logged, but the request gets back a 'not authorized', so it definitely hit the right place.

Any ideas on why it's not showing up in Firebug so I can verify the headers are being sent out correctly?

+1  A: 

I would say it's because you don't have a ',' before url...

$.ajax({
    type: "GET",
    contentType: 'application/json',
        beforeSend:function(xhr){
        xhr.setRequestHeader("Authentication", "Basic " + base64EncodedValue);
    }
    ,url: 'https://api.company.com/uri/',
    complete: function(result) {
       alert(result);
    }
});

could be wrong, but that's my guess,

Andrew

Andrew