Emre Erol
Emre Erol

Reputation: 460

Classic Asp Persits Upload And Jquery Ajax

I have one file input and i want to upload selected file with jquery ajax.

My input like this

<form id="formWithFiles">    
  <input type="file" name="file">
</form>

My upload jquery code

$("input[name='file']").on('change',function(){
  $.ajax({
    url: 'du.asp', 
    type: 'POST',
    contentType:'multipart/form-data',
    data: new FormData($('#formWithFiles')[0]),
    processData: false, 
    success:function(data){
      console.log(data);
    }
  });
});

My Upload Classic Asp Code - du.asp

Set Upload = Server.CreateObject("Persits.Upload")
Upload.CodePage = 65001
Upload.OverwriteFiles = False
Temp = Server.MapPath("content/temp")&"/"
Upload.Save(Temp)

Problem is here; I am getting a

500 Internal Server Error

error with jquery ajax. But if i use form submit method then file uploading with du.asp.

Detailed Error (Just using ajax)

Boundary not found in Content-Type. Make sure you have included the attribute ENCTYPE="multipart/form-data" in your form.

Upvotes: 2

Views: 3529

Answers (1)

Emre Erol
Emre Erol

Reputation: 460

I did it with this code;

var formData = new FormData($("#formWithFiles")[0]);

    $.ajax({
        url: 'du.asp',
        type: 'POST',
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (returndata) {
            console.log(returndata);
        }
    });

Upvotes: 2

Related Questions