Trouble getting started: would you kindly tell me what is wrong with this jQuery ajax request?
Here is a super-basic jQuery call to list my lighthouse projects. It doesn't work, returning a 302 redirect to http://xxxx.lighthouse.app/login What am I doing wrong here?
I can curl using the same url and api key and that works just
fine, so I know the api key is valid...
curl -H 'X-LighthouseToken:xxxxxxx' http://xxxxx.lighthouseapp.com/projects.json
Thanks for reading!
LightHouse = {};
LightHouse.apiToken = 'xxxxxxxxxxxxxx';
LightHouse.baseURL = 'http://xxxxx.lighthouseapp.com/';
LightHouse.getProjects = function(callback) {
var url = LightHouse.baseURL + 'projects.json';
$.ajax({
url: url,
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-Type","application/json");
xhr.setRequestHeader('X-LighthouseToken', LightHouse.apiToken);
},
success: function( data, textStatus, jqXHR ) {
var returnVal = $.parseJSON(data);
console.log(returnVal);
}
});
};
Discussions are closed to public comments.
If you need help with Lighthouse please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Tiger Team on 11 Dec, 2013 12:38 AM
Is this code going to be public anywhere? Your token can be used for all sorts of evil.
2 Posted by Shaun Reynolds on 11 Dec, 2013 12:39 AM
No, it won't be public. I'm just making some simple scripts to automate ticket tracking for some internal tools.
Support Staff 3 Posted by Tiger Team on 11 Dec, 2013 12:42 AM
I see a bunch of requests sending OPTIONS requests instead of GET. Your ajax request isn't working...
site:77075 user:nil [302 Found] OPTIONS /projects.json action= params={"method"=>:get, "paths"=>["projects.json"]} format=*/* ip=76.14.71.239 location=http://owngroup.lighthouseapp.com/login duration=5ms db=1ms
4 Posted by Shaun Reynolds on 11 Dec, 2013 01:02 AM
I figured it out. jQuery was setting headers in such a way that it was triggering a cross-site scripting preflight request.
setting a dataType of 'jsonp' fixed it...
5 Posted by Shaun Reynolds on 11 Dec, 2013 01:03 AM
Thanks for your very prompt responses :)
Support Staff 6 Posted by Tiger Team on 11 Dec, 2013 01:14 AM
no worries good luck getting it all integrated!