1

I am trying to use the Kippt API with $.ajax.

When I use

curl -X GET -H "X-Kippt-Username:graph1ZzLle" -H "X-Kippt-API-Token:mytoken" https://kippt.com/api/clips/ 

Everything is running fine and I am getting the JSON response.

However, when it comes to use jQuery with this script :

<script type="text/javascript"> var username = "graph1ZzLle"; var token = "*******"; $(document).ready(function() { $.ajax({ url: "https://kippt.com/api/clips/?list=all&include_data=list&limit=10", type: 'GET', dataType: 'jsonp', async: false, beforeSend: function(xhr) { xhr.setRequestHeader('X-Kippt-Username', username) xhr.setRequestHeader('X-Kippt-API-Token', token) }, success: function(data) { for(var i = 0; i < data.objects.length; i++) { var row = $("<tr/>"); var date = new Date(data.objects[i]["created"] * 1000); //js works in milliseconds $("<td/>").text(date.toLocaleDateString()).appendTo(row); $("<td/>").text(data.objects[i]["list"]["title"]).appendTo(row); $("<td/>").append("<a href=" + data.objects[i]["url"] + " >" + data.objects[i]["title"] + "</a>").appendTo(row); if(data.objects[i]["notes"]) { $("<td/>").text(data.objects[i]["notes"]).appendTo(row); } else { $("<td/>").text("-----").appendTo(row); } row.appendTo("#kippt"); } }, }); }); </script> 

I am always gettin the 401 (UNAUTHORIZED) error. I am sure I am using the correct username and token. What is going on ?

1
  • 2
    you can't set headers with the JSONP dataType. JSONP requests are created by inserting a <script> tag into the document with a src set to the target location. Commented Feb 21, 2013 at 16:16

1 Answer 1

5

you can't set headers with the JSONP dataType. JSONP requests are created by inserting a <script> tag into the document with a src set to the target location, and since you can't pass headers with a tag, your header settings are ignored.

Either use CORS and JSON, or a server-side proxy that gets the data for you.

Sign up to request clarification or add additional context in comments.

1 Comment

well, I will try using the classic XMLHttpRequest object

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.