javascriptjqueryjspmultipartcontenttype

how to set contenttype in form?


Here i need to set contenttype="multipart/form-data" while form submit but its fail it's assign contenttype="text/html" how to change?

refButton = '<form id="importForm" action="http://localhost:8080/bwsim/UploadScenario" class="userInputForm" enctype="multipart/form-data">' +
         '<input id="file" name="file" type="file" />' +
         '</form>';
         document.getElementById("popupDiv").innerHTML = refButton;
         $("#popupDiv").dialog({
             title: "Import Scenario",
             draggable: true,
             bgiframe: true,
             modal: true,
             width: 500,
             heigth: 100,
             show: {effect: 'blind', duration: 500},
             hide: {effect: 'fade', duration: 1000},
             zIndex: 1000,
             buttons: {
                 'Upload': function() {
                     if ($("#importForm").valid()) {
                         document.forms["importForm"].submit();
                         $(this).dialog("close");
                      }
                 },
                 'Cancel': function() {
                     $(this).dialog("close");
                 }
             }
         });

Solution

  • its fail it's assign contenttype="text/html" how to change?

    No, it isn't.

    Your form doesn't have a method attribute, so it is defaulting to GET.

    GET requests don't have request bodies, so there is no content to describe the content-type of.

    Add method="POST" to your form start tag.