0

my code is below. when I put this code i got error "illegal invocation".Can anyone help me to solve this issue?

const blob = new Blob([content], { type: "application/json" });
const file = new File([blob], sName);
const formData = new FormData();
formData.append("swagger_file", file, sName);
formData.append("swagger_file_name", sName);
formData.append("file_version", sVersion);
url='/publisher/assets/swagger/apis/swaggers';

$.ajax({
              type: "POST",
               url: url,
              data: formData,
              success: function() {
              window.location.replace("/publisher/assets/swagger/list");
             },
             error: function( errorThrown ){
              debugger;
              console.log( "errorThrown",errorThrown );
          }

            });
Tharmini
  • 103
  • 4
  • 1
    `i got error "illegal invocation"` which line throws that error - is this an error in the AJAX response - the code you posted, assuming the variables are defined somewhere, won't throw that error - if the error is what is in `errorThrown`, then the issue is possibly with the server side code, or that you're sending something the server isn't expecting - either way, need to see the server side code this is POSTing to – Bravo Oct 10 '19 at 06:49
  • 1
    This is (usually) an error that jQuery throws when invoking `.ajax`. The reasons are that you are *somehow* sending something that's not valid and jQuery cannot formulate a proper request. Usually, you need the proper options set for that call. Since you are trying to send `FormData`, [try following these suggestions](https://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax) and set the options there, one or more of those might be relevant. – VLAZ Oct 10 '19 at 06:59
  • 1
    Just as a quick summary of the other answers, it seems that you might need `processData: false` and `contentType: false` added as options. – VLAZ Oct 10 '19 at 07:00
  • Thanks for your answer..now i add `processData: false` and `contentType: false` option. now my problem is resolved. – Tharmini Oct 10 '19 at 07:19
  • Possible duplicate of [Sending multipart/formdata with jQuery.ajax](https://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax) – VLAZ Oct 10 '19 at 07:45

0 Answers0