0

I have some HTML content and need to pass it to the back end via FormData.append. When I try to pass it like HTML contents it shows me Internal Server 500 error. When I pass just text then it successfully hit to the backend.

Code

 var _description = "<p><b>Test Description</b></p>";
 var formData = new FormData();
 formData.append("Description", _description)

Then Send it to the backend via AJAX Call,

 $.ajax({
            url: $("#addNewsDetails").val(),
           // cache: false,
            type: "POST",
            data: formData,
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            mimeType: 'multipart/form-data',
            processData: false,
            contentType: false,
            success: function (status) {
               //Success
            }
        });
TechGuy
  • 4,298
  • 15
  • 56
  • 87
  • your code works fine for me without any exception. probably you are processing data that is causing issue. do you have a try-catch block? actual exception would be in catch block. regardless, you have duplicate declaration of "contentType" in ajax call. – Pirate May 25 '20 at 12:53

1 Answers1

0

The server is probably configured to not accept html. You could maybe try to change that setting, or alternatively you could encode the html before the ajax call. Then on the server you would need to decode it.

Cosmin
  • 2,365
  • 2
  • 23
  • 29