0

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

Manish Kumar
  • 10,214
  • 25
  • 77
  • 147

1 Answers1

0

Since you're making a POST request, you need to pass the token & url values as a data object instead.

$(function() {
    $("#btn").click(function(){
        $.ajax({
            type: "POST",
            url: "https://crocodoc.com/api/v2/document/upload",
            data: {
                token: "XYZ",
                url: "http://web.crocodoc.com/files/test-simple.pdf"
            },
            success: function (data, textStatus, jqXHR) {
                console.log("ok", data);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log("failed", jqXHR, textStatus, errorThrown);
            }
        })
    });
});

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

Community
  • 1
  • 1
Dennis Plucinik
  • 224
  • 3
  • 8