1
votes

I'm having an issue getting this jQuery.ajax call to work. When the script executes I get an error (textStatus = "error"), but no error message (errorThrown = "").

$.ajax({
    type: 'GET',
    url: 'http://www.kanbanpad.com/api/v1/projects.json',
    username: '[email protected]',
    password: 'myAPIkey',
    dataType: 'json',
    success: function(data) {
        alert(data);
    },
    error: function(jqXHR, textStatus, errorThrown) {
        alert(textStatus+': '+errorThrown);
    }
});

If I manually hit the API URL (above) and type in my login credentials, I do get the proper JSON response. So, I'm not sure what I'm doing wrong. Is my code malformed?

If you need more information about the API, go to http://www.kanbanpad.com/api/v1

3
what does the jqXHR object have to say? - DefyGravity
@DefyGravity I don't know what you're asking, can you be more specific? - therealklanni
in function error :function(jqXHR, textStatus, errorthrown){ alert(JSON.stringify(jqXHR));} JSON is from www.json.org. or just look at it in a js debugger ;) - DefyGravity
The jqXHR object is {"readyState":0,"responseText":"","status":0,"statusText":"error"} - therealklanni
If I try jsonp dataType, I get {"readyState":4,"status":200,"statusText":"parsererror"} as the jqXHR object and errorThrown = jQuery15108416848906781524_1299986108143 was not called which is odd, since according to jQuery documentation error: function(){ should never be called when dataType is jsonp. - therealklanni

3 Answers

1
votes

That page is using HTTP basic auth but you are simply posting a username/password in your request. You have to properly set up the auth tokens and pass them in a header. Here is a simple tutorial on HTTP basic auth over AJAX--notice there is a jQuery specific example for the AJAX part.

0
votes

Here is the fix:

Change URL value to http://username%40domain.com:[email protected]/api/v1...

For whatever reason, jQuery (1.5.1, also tried with 1.4.4) is not passing the username and password parameters to the web server correctly (or not at all?), so rather than use those parameters, it can authenticate by including the credentials in the URL string.

0
votes