I am trying to upload a file in Crocodoc as below
$(function() {
$("#btn").click(function(){
$.ajax({
type:"POST",
url:"https://crocodoc.com/api/v2/document/upload?token=XYZ&url=http://web.crocodoc.com/files/test-simple.pdf",
success:function(data){
alert("ok"+data);
},
error:function(data)
{
alert("failed"+data.error);
}
})
});
});
In firebug i see a “401 UNAUTHORIZED” error.What is the problem pls help.I am passing the correct token key
Since you’re making a POST request, you need to pass the token & url values as a data object instead.
Also, using console to log your output will give you more meaningful debug information than an alert.
Lastly, and to answer your actual question you can’t upload a file like this. You need a form submission. See here: jQuery Ajax File Upload