1

I want the following code

var request = new XMLHttpRequest();
    request.open("PUT", dbServer + "/configItemAdd");
    request.send(new FormData(form));
    request.onreadystatechange = function () {
        if(request.readyState == 4 && request.status == 200) {   window.location.reload(); }
};

to look like this

     const fd = new FormData(form);
     $http({
         method: 'PUT',
         url: dbServer + "/configItemAdd",
         data: fd
     }).then(function (resp){
         window.location.reload();
     });

the problem is I get two error messages: with just labels and no file input I get SyntaxError: Unexpected token # in JSON at position 0

and with file input I get PayloadTooLargeError: request entity too large

the XMLHttpRequest code is working with and without input files. Please help :S

1
  • you need to set headers as Content-Type', 'multipart/form-data' as well Commented Dec 20, 2017 at 9:36

1 Answer 1

1

You have to add an extra header i.e. {'Content-Type': 'multipart/form-data'} to your request

const fd = new FormData(form);
 $http({
     method: 'PUT',
     url: dbServer + "/configItemAdd",
     Content-Type: 'multipart/form-data'
     data: fd
 }).then(function (resp){
     window.location.reload();
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.